TF-4178 Add datasource/repository/interactor for create new label

This commit is contained in:
dab246
2025-11-26 16:32:53 +07:00
committed by Dat H. Pham
parent 8f1da20e54
commit 38c47ca373
10 changed files with 128 additions and 22 deletions
@@ -3,4 +3,6 @@ import 'package:labels/model/label.dart';
abstract class LabelRepository {
Future<List<Label>> getAllLabels(AccountId accountId);
Future<Label> createNewLabel(AccountId accountId, Label labelData);
}
@@ -0,0 +1,18 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:labels/model/label.dart';
class CreatingNewLabel extends LoadingState {}
class CreateNewLabelSuccess extends UIState {
final Label newLabel;
CreateNewLabelSuccess(this.newLabel);
@override
List<Object> get props => [newLabel];
}
class CreateNewLabelFailure extends FeatureFailure {
CreateNewLabelFailure(dynamic exception) : super(exception: exception);
}
@@ -0,0 +1,29 @@
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/model/label.dart';
import 'package:tmail_ui_user/features/labels/domain/repository/label_repository.dart';
import 'package:tmail_ui_user/features/labels/domain/state/create_new_label_state.dart';
class CreateNewLabelInteractor {
final LabelRepository _labelRepository;
CreateNewLabelInteractor(this._labelRepository);
Stream<Either<Failure, Success>> execute(
AccountId accountId,
Label labelData,
) async* {
try {
yield Right(CreatingNewLabel());
final newLabel = await _labelRepository.createNewLabel(
accountId,
labelData,
);
yield Right(CreateNewLabelSuccess(newLabel));
} catch (e) {
yield Left(CreateNewLabelFailure(e));
}
}
}