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