From d3b3be83b698fa994c05ce48953b0a967c8b93b2 Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 17 Aug 2022 20:22:53 +0700 Subject: [PATCH] TF-801 Add domain layer for update vacation --- .../repository/manage_account_repository.dart | 2 ++ .../domain/state/get_all_vacation_state.dart | 2 +- .../domain/state/update_vacation_state.dart | 29 +++++++++++++++++++ .../usecases/update_vacation_interactor.dart | 25 ++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lib/features/manage_account/domain/state/update_vacation_state.dart create mode 100644 lib/features/manage_account/domain/usecases/update_vacation_interactor.dart diff --git a/lib/features/manage_account/domain/repository/manage_account_repository.dart b/lib/features/manage_account/domain/repository/manage_account_repository.dart index 81bd2eb89..26cdf0e43 100644 --- a/lib/features/manage_account/domain/repository/manage_account_repository.dart +++ b/lib/features/manage_account/domain/repository/manage_account_repository.dart @@ -35,4 +35,6 @@ abstract class ManageAccountRepository { Future getForward(AccountId accountId); Future> getAllVacationResponse(AccountId accountId); + + Future> updateVacation(AccountId accountId, VacationResponse vacationResponse); } \ No newline at end of file diff --git a/lib/features/manage_account/domain/state/get_all_vacation_state.dart b/lib/features/manage_account/domain/state/get_all_vacation_state.dart index afdbd1d27..f8d5df82c 100644 --- a/lib/features/manage_account/domain/state/get_all_vacation_state.dart +++ b/lib/features/manage_account/domain/state/get_all_vacation_state.dart @@ -11,7 +11,7 @@ class LoadingGetAllVacation extends UIState { } class GetAllVacationSuccess extends UIState { - final List? listVacationResponse; + final List listVacationResponse; GetAllVacationSuccess(this.listVacationResponse); diff --git a/lib/features/manage_account/domain/state/update_vacation_state.dart b/lib/features/manage_account/domain/state/update_vacation_state.dart new file mode 100644 index 000000000..e2c3c6500 --- /dev/null +++ b/lib/features/manage_account/domain/state/update_vacation_state.dart @@ -0,0 +1,29 @@ +import 'package:core/presentation/state/failure.dart'; +import 'package:core/presentation/state/success.dart'; +import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart'; + +class LoadingUpdateVacation extends UIState { + + LoadingUpdateVacation(); + + @override + List get props => []; +} + +class UpdateVacationSuccess extends UIState { + final List listVacationResponse; + + UpdateVacationSuccess(this.listVacationResponse); + + @override + List get props => [listVacationResponse]; +} + +class UpdateVacationFailure extends FeatureFailure { + final dynamic exception; + + UpdateVacationFailure(this.exception); + + @override + List get props => [exception]; +} \ No newline at end of file diff --git a/lib/features/manage_account/domain/usecases/update_vacation_interactor.dart b/lib/features/manage_account/domain/usecases/update_vacation_interactor.dart new file mode 100644 index 000000000..b6234d57b --- /dev/null +++ b/lib/features/manage_account/domain/usecases/update_vacation_interactor.dart @@ -0,0 +1,25 @@ +import 'dart:core'; + +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:jmap_dart_client/jmap/mail/vacation/vacation_response.dart'; +import 'package:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.dart'; +import 'package:tmail_ui_user/features/manage_account/domain/state/update_vacation_state.dart'; + +class UpdateVacationInteractor { + final ManageAccountRepository manageAccountRepository; + + UpdateVacationInteractor(this.manageAccountRepository); + + Stream> execute(AccountId accountId, VacationResponse vacationResponse) async* { + try { + yield Right(LoadingUpdateVacation()); + final listVacationResponse = await manageAccountRepository.updateVacation(accountId, vacationResponse); + yield Right(UpdateVacationSuccess(listVacationResponse)); + } catch (exception) { + yield Left(UpdateVacationFailure(exception)); + } + } +} \ No newline at end of file