TF-4243 Add datasource/repository/interactor for delete a label feature

This commit is contained in:
dab246
2026-01-12 15:22:54 +07:00
committed by Dat H. Pham
parent 5914877b1b
commit 327d05d20b
7 changed files with 86 additions and 0 deletions
@@ -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);
}
}
}