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