TF-939 Implement VacationRepository

This commit is contained in:
Dat PHAM HOANG
2022-09-14 17:28:49 +07:00
committed by Dat H. Pham
parent 5605e22bbf
commit 2f48c1eee5
4 changed files with 105 additions and 49 deletions
@@ -0,0 +1,28 @@
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/data/datasource/vacation_data_source.dart';
import 'package:tmail_ui_user/features/manage_account/data/network/vacation_api.dart';
class VacationDataSourceImpl extends VacationDataSource {
final VacationAPI _vacationAPI;
VacationDataSourceImpl(this._vacationAPI);
@override
Future<List<VacationResponse>> getAllVacationResponse(AccountId accountId) {
return Future.sync(() async {
return await _vacationAPI.getAllVacationResponse(accountId);
}).catchError((error) {
throw error;
});
}
@override
Future<List<VacationResponse>> updateVacation(AccountId accountId, VacationResponse vacationResponse) {
return Future.sync(() async {
return await _vacationAPI.updateVacation(accountId, vacationResponse);
}).catchError((error) {
throw error;
});
}
}
@@ -16,11 +16,6 @@ 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';
import 'package:rule_filter/rule_filter/rule_filter_id.dart';
@@ -218,50 +213,6 @@ class ManageAccountAPI {
return tMailForwardResult;
}
Future<List<VacationResponse>> getAllVacationResponse(AccountId accountId) async {
final processingInvocation = ProcessingInvocation();
final requestBuilder = JmapRequestBuilder(_httpClient, processingInvocation);
final getVacationMethod = GetVacationMethod(accountId);
final getVacationInvocation = requestBuilder.invocation(getVacationMethod);
final response = await (requestBuilder
..usings(getVacationMethod.requiredCapabilities))
.build()
.execute();
final resultList = response.parse<GetVacationResponse>(
getVacationInvocation.methodCallId,
GetVacationResponse.deserialize);
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>[];
}
Future<TMailForward> updateForward(AccountId accountId, TMailForward forward) async {
final setForwardMethod = SetForwardMethod(accountId)
..addUpdatesSingleton({
@@ -0,0 +1,57 @@
import 'package:jmap_dart_client/http/http_client.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/jmap_request.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/set/set_vacation_method.dart';
import 'package:jmap_dart_client/jmap/mail/vacation/vacation_id.dart';
import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart';
class VacationAPI {
final HttpClient _httpClient;
VacationAPI(this._httpClient);
Future<List<VacationResponse>> getAllVacationResponse(AccountId accountId) async {
final processingInvocation = ProcessingInvocation();
final requestBuilder = JmapRequestBuilder(_httpClient, processingInvocation);
final getVacationMethod = GetVacationMethod(accountId);
final getVacationInvocation = requestBuilder.invocation(getVacationMethod);
final response = await (requestBuilder
..usings(getVacationMethod.requiredCapabilities))
.build()
.execute();
final resultList = response.parse<GetVacationResponse>(
getVacationInvocation.methodCallId,
GetVacationResponse.deserialize);
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>[];
}
}
@@ -0,0 +1,20 @@
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/data/datasource/vacation_data_source.dart';
import 'package:tmail_ui_user/features/manage_account/domain/repository/vacation_repository.dart';
class VacationRepositoryImpl extends VacationRepository {
final VacationDataSource dataSource;
VacationRepositoryImpl(this.dataSource);
@override
Future<List<VacationResponse>> getAllVacationResponse(AccountId accountId) {
return dataSource.getAllVacationResponse(accountId);
}
@override
Future<List<VacationResponse>> updateVacation(AccountId accountId, VacationResponse vacationResponse) {
return dataSource.updateVacation(accountId, vacationResponse);
}
}