From f3e6d892d833fa6f0bb15b5bc5b5e85ed7c8e85a Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 17 Aug 2022 20:22:59 +0700 Subject: [PATCH] TF-801 Add data layer for update vacation --- .../datasource/manage_account_datasource.dart | 2 ++ .../manage_account_datasource_impl.dart | 9 +++++++ .../data/network/manage_account_api.dart | 27 +++++++++++++++++++ .../manage_account_repository_impl.dart | 5 ++++ 4 files changed, 43 insertions(+) diff --git a/lib/features/manage_account/data/datasource/manage_account_datasource.dart b/lib/features/manage_account/data/datasource/manage_account_datasource.dart index 5da9b1ef7..fb8ec634f 100644 --- a/lib/features/manage_account/data/datasource/manage_account_datasource.dart +++ b/lib/features/manage_account/data/datasource/manage_account_datasource.dart @@ -35,4 +35,6 @@ abstract class ManageAccountDataSource { 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/data/datasource_impl/manage_account_datasource_impl.dart b/lib/features/manage_account/data/datasource_impl/manage_account_datasource_impl.dart index e231c789f..ea9def7cd 100644 --- a/lib/features/manage_account/data/datasource_impl/manage_account_datasource_impl.dart +++ b/lib/features/manage_account/data/datasource_impl/manage_account_datasource_impl.dart @@ -126,4 +126,13 @@ class ManageAccountDataSourceImpl extends ManageAccountDataSource { throw error; }); } + + @override + Future> updateVacation(AccountId accountId, VacationResponse vacationResponse) { + return Future.sync(() async { + return await manageAccountAPI.updateVacation(accountId, vacationResponse); + }).catchError((error) { + throw error; + }); + } } \ No newline at end of file diff --git a/lib/features/manage_account/data/network/manage_account_api.dart b/lib/features/manage_account/data/network/manage_account_api.dart index 2b1306ea9..83fa031f9 100644 --- a/lib/features/manage_account/data/network/manage_account_api.dart +++ b/lib/features/manage_account/data/network/manage_account_api.dart @@ -15,8 +15,10 @@ import 'package:jmap_dart_client/jmap/identities/identity.dart'; import 'package:jmap_dart_client/jmap/identities/set/set_identity_method.dart'; import 'package:jmap_dart_client/jmap/identities/set/set_identity_response.dart'; import 'package:jmap_dart_client/jmap/jmap_request.dart'; +import 'package:jmap_dart_client/jmap/mail/vacation/set/set_vacation_method.dart'; import 'package:jmap_dart_client/jmap/mail/vacation/get/get_vacation_method.dart'; import 'package:jmap_dart_client/jmap/mail/vacation/get/get_vacation_response.dart'; +import 'package:jmap_dart_client/jmap/mail/vacation/vacation_id.dart'; import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart'; import 'package:rule_filter/rule_filter/get/get_rule_filter_method.dart'; import 'package:rule_filter/rule_filter/get/get_rule_filter_response.dart'; @@ -233,4 +235,29 @@ class ManageAccountAPI { return resultList?.list ?? []; } + + Future> updateVacation(AccountId accountId, VacationResponse vacationResponse) async { + final setVacationMethod = SetVacationMethod(accountId) + ..addUpdatesSingleton({ + VacationId.singleton().id : vacationResponse + }); + + final processingInvocation = ProcessingInvocation(); + final requestBuilder = JmapRequestBuilder(_httpClient, processingInvocation) + ..invocation(setVacationMethod); + + final getVacationMethod = GetVacationMethod(accountId); + final getVacationInvocation = requestBuilder.invocation(getVacationMethod); + + final response = await (requestBuilder + ..usings(setVacationMethod.requiredCapabilities)) + .build() + .execute(); + + final resultList = response.parse( + getVacationInvocation.methodCallId, + GetVacationResponse.deserialize); + + return resultList?.list ?? []; + } } \ No newline at end of file diff --git a/lib/features/manage_account/data/repository/manage_account_repository_impl.dart b/lib/features/manage_account/data/repository/manage_account_repository_impl.dart index 9f8d38e9c..5b4446cae 100644 --- a/lib/features/manage_account/data/repository/manage_account_repository_impl.dart +++ b/lib/features/manage_account/data/repository/manage_account_repository_impl.dart @@ -75,4 +75,9 @@ class ManageAccountRepositoryImpl extends ManageAccountRepository { Future> getAllVacationResponse(AccountId accountId) { return dataSource.getAllVacationResponse(accountId); } + + @override + Future> updateVacation(AccountId accountId, VacationResponse vacationResponse) { + return dataSource.updateVacation(accountId, vacationResponse); + } } \ No newline at end of file