TF-4243 Add datasource/repository/interactor for delete a label feature
This commit is contained in:
@@ -8,4 +8,6 @@ abstract class LabelDatasource {
|
||||
Future<Label> createNewLabel(AccountId accountId, Label labelData);
|
||||
|
||||
Future<Label> editLabel(AccountId accountId, EditLabelRequest labelRequest);
|
||||
|
||||
Future<void> deleteLabel(AccountId accountId, Label label);
|
||||
}
|
||||
|
||||
@@ -31,4 +31,11 @@ class LabelDatasourceImpl extends LabelDatasource {
|
||||
return await _labelApi.editLabel(accountId, labelRequest);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteLabel(AccountId accountId, Label label) {
|
||||
return Future.sync(() async {
|
||||
return await _labelApi.deleteLabel(accountId, label);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:jmap_dart_client/jmap/jmap_request.dart';
|
||||
import 'package:labels/labels.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/handle_error_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/model/edit_label_request.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/exceptions/label_exceptions.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class LabelApi with HandleSetErrorMixin {
|
||||
@@ -96,4 +97,29 @@ class LabelApi with HandleSetErrorMixin {
|
||||
throw parseErrorForSetResponse(response, labelId);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteLabel(AccountId accountId, Label label) async {
|
||||
final labelId = label.id;
|
||||
|
||||
if (labelId == null) {
|
||||
throw LabelIdIsNull();
|
||||
}
|
||||
|
||||
final method = SetLabelMethod(accountId)..addDestroy({labelId});
|
||||
|
||||
final builder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
final invocation = builder.invocation(method);
|
||||
|
||||
final result =
|
||||
await (builder..usings(method.requiredCapabilities)).build().execute();
|
||||
|
||||
final response = result.parse<SetLabelResponse>(
|
||||
invocation.methodCallId,
|
||||
SetLabelResponse.deserialize,
|
||||
);
|
||||
|
||||
if (response?.destroyed?.contains(labelId) != true) {
|
||||
throw parseErrorForSetResponse(response, labelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,9 @@ class LabelRepositoryImpl extends LabelRepository {
|
||||
Future<Label> editLabel(AccountId accountId, EditLabelRequest labelRequest) {
|
||||
return _labelDatasource.editLabel(accountId, labelRequest);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteLabel(AccountId accountId, Label label) {
|
||||
return _labelDatasource.deleteLabel(accountId, label);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user