TF-801 Add data layer for update vacation

This commit is contained in:
dab246
2022-08-17 20:22:59 +07:00
committed by Dat H. Pham
parent d3b3be83b6
commit f3e6d892d8
4 changed files with 43 additions and 0 deletions
@@ -35,4 +35,6 @@ abstract class ManageAccountDataSource {
Future<TMailForward> getForward(AccountId accountId);
Future<List<VacationResponse>> getAllVacationResponse(AccountId accountId);
Future<List<VacationResponse>> updateVacation(AccountId accountId, VacationResponse vacationResponse);
}
@@ -126,4 +126,13 @@ class ManageAccountDataSourceImpl extends ManageAccountDataSource {
throw error;
});
}
@override
Future<List<VacationResponse>> updateVacation(AccountId accountId, VacationResponse vacationResponse) {
return Future.sync(() async {
return await manageAccountAPI.updateVacation(accountId, vacationResponse);
}).catchError((error) {
throw error;
});
}
}
@@ -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 ?? <VacationResponse>[];
}
Future<List<VacationResponse>> 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<GetVacationResponse>(
getVacationInvocation.methodCallId,
GetVacationResponse.deserialize);
return resultList?.list ?? <VacationResponse>[];
}
}
@@ -75,4 +75,9 @@ class ManageAccountRepositoryImpl extends ManageAccountRepository {
Future<List<VacationResponse>> getAllVacationResponse(AccountId accountId) {
return dataSource.getAllVacationResponse(accountId);
}
@override
Future<List<VacationResponse>> updateVacation(AccountId accountId, VacationResponse vacationResponse) {
return dataSource.updateVacation(accountId, vacationResponse);
}
}