TF-4171 Add datasource/repository/interactor for get all labels
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
|
||||
abstract class LabelRepository {
|
||||
Future<List<Label>> getAllLabels(AccountId accountId);
|
||||
}
|
||||
@@ -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 GettingAllLabel extends LoadingState {}
|
||||
|
||||
class GetAllLabelSuccess extends UIState {
|
||||
final List<Label> labels;
|
||||
|
||||
GetAllLabelSuccess(this.labels);
|
||||
|
||||
@override
|
||||
List<Object> get props => [labels];
|
||||
}
|
||||
|
||||
class GetAllLabelFailure extends FeatureFailure {
|
||||
GetAllLabelFailure(dynamic exception) : super(exception: exception);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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:tmail_ui_user/features/labels/domain/repository/label_repository.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/state/get_all_label_state.dart';
|
||||
|
||||
class GetAllLabelInteractor {
|
||||
final LabelRepository _labelRepository;
|
||||
|
||||
GetAllLabelInteractor(this._labelRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
try {
|
||||
yield Right(GettingAllLabel());
|
||||
final labels = await _labelRepository.getAllLabels(accountId);
|
||||
yield Right(GetAllLabelSuccess(labels));
|
||||
} catch (e) {
|
||||
yield Left(GetAllLabelFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user