TF-4171 Add datasource/repository/interactor for get all labels

This commit is contained in:
dab246
2025-11-25 00:11:16 +07:00
committed by Dat H. Pham
parent 4af0ee1086
commit f4302e06e8
15 changed files with 250 additions and 0 deletions
@@ -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));
}
}
}