TF-4243 Add datasource/repository/interactor for delete a label feature
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user