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
@@ -8,4 +8,6 @@ abstract class LabelRepository {
Future<Label> createNewLabel(AccountId accountId, Label labelData);
Future<Label> editLabel(AccountId accountId, EditLabelRequest labelRequest);
Future<void> deleteLabel(AccountId accountId, Label label);
}
@@ -0,0 +1,17 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class DeletingALabel extends LoadingState {}
class DeleteALabelSuccess extends UIState {
final String labelDisplayName;
DeleteALabelSuccess(this.labelDisplayName);
@override
List<Object> get props => [labelDisplayName];
}
class DeleteALabelFailure extends FeatureFailure {
DeleteALabelFailure(dynamic exception) : super(exception: exception);
}
@@ -0,0 +1,27 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:labels/extensions/label_extension.dart';
import 'package:labels/model/label.dart';
import 'package:tmail_ui_user/features/labels/domain/repository/label_repository.dart';
import 'package:tmail_ui_user/features/labels/domain/state/delete_a_label_state.dart';
class DeleteALabelInteractor {
final LabelRepository _labelRepository;
DeleteALabelInteractor(this._labelRepository);
Stream<Either<Failure, Success>> execute(
AccountId accountId,
Label label,
) async* {
try {
yield Right(DeletingALabel());
await _labelRepository.createNewLabel(accountId, label);
yield Right(DeleteALabelSuccess(label.safeDisplayName));
} catch (e) {
yield Left(DeleteALabelFailure(e));
}
}
}