TF-4233 Implement edit label action

This commit is contained in:
dab246
2026-01-05 16:36:06 +07:00
committed by Dat H. Pham
parent 0302e09981
commit bac101021e
17 changed files with 376 additions and 66 deletions
@@ -0,0 +1,19 @@
import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
import 'package:labels/model/label.dart';
class EditLabelRequest with EquatableMixin {
final Id labelId;
final KeyWordIdentifier? labelKeyword;
final Label newLabel;
EditLabelRequest({
required this.labelId,
required this.labelKeyword,
required this.newLabel,
});
@override
List<Object?> get props => [labelId, labelKeyword, newLabel];
}
@@ -1,8 +1,11 @@
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:labels/model/label.dart';
import 'package:tmail_ui_user/features/labels/domain/model/edit_label_request.dart';
abstract class LabelRepository {
Future<List<Label>> getAllLabels(AccountId accountId);
Future<Label> createNewLabel(AccountId accountId, Label labelData);
Future<Label> editLabel(AccountId accountId, EditLabelRequest labelRequest);
}
@@ -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 EditingLabel extends LoadingState {}
class EditLabelSuccess extends UIState {
final Label newLabel;
EditLabelSuccess(this.newLabel);
@override
List<Object> get props => [newLabel];
}
class EditLabelFailure extends FeatureFailure {
EditLabelFailure(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:tmail_ui_user/features/labels/domain/model/edit_label_request.dart';
import 'package:tmail_ui_user/features/labels/domain/repository/label_repository.dart';
import 'package:tmail_ui_user/features/labels/domain/state/edit_label_state.dart';
class EditLabelInteractor {
final LabelRepository _labelRepository;
EditLabelInteractor(this._labelRepository);
Stream<Either<Failure, Success>> execute(
AccountId accountId,
EditLabelRequest labelRequest,
) async* {
try {
yield Right(EditingLabel());
final newLabel = await _labelRepository.editLabel(
accountId,
labelRequest,
);
yield Right(EditLabelSuccess(newLabel));
} catch (e) {
yield Left(EditLabelFailure(e));
}
}
}