TF-460 Add data layer for implement get all identities
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
|
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
|
||||||
|
|
||||||
|
abstract class ManageAccountDataSource {
|
||||||
|
Future<IdentitiesResponse> getAllIdentities(AccountId accountId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
|
import 'package:tmail_ui_user/features/manage_account/data/datasource/manage_account_datasource.dart';
|
||||||
|
import 'package:tmail_ui_user/features/manage_account/data/network/manage_account_api.dart';
|
||||||
|
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
|
||||||
|
|
||||||
|
class ManageAccountDataSourceImpl extends ManageAccountDataSource {
|
||||||
|
|
||||||
|
final ManageAccountAPI manageAccountAPI;
|
||||||
|
|
||||||
|
ManageAccountDataSourceImpl(this.manageAccountAPI);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<IdentitiesResponse> getAllIdentities(AccountId accountId) {
|
||||||
|
return Future.sync(() async {
|
||||||
|
return await manageAccountAPI.getAllIdentities(accountId);
|
||||||
|
}).catchError((error) {
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:jmap_dart_client/http/http_client.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/identities/get/get_identity_method.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/identities/get/get_identity_response.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/jmap_request.dart';
|
||||||
|
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
|
||||||
|
|
||||||
|
class ManageAccountAPI {
|
||||||
|
|
||||||
|
final HttpClient _httpClient;
|
||||||
|
|
||||||
|
ManageAccountAPI(this._httpClient);
|
||||||
|
|
||||||
|
Future<IdentitiesResponse> getAllIdentities(AccountId accountId) async {
|
||||||
|
final processingInvocation = ProcessingInvocation();
|
||||||
|
final jmapRequestBuilder = JmapRequestBuilder(_httpClient, processingInvocation);
|
||||||
|
final getIdentityMethod = GetIdentityMethod(accountId);
|
||||||
|
final queryInvocation = jmapRequestBuilder.invocation(getIdentityMethod);
|
||||||
|
|
||||||
|
final result = await (jmapRequestBuilder
|
||||||
|
..usings(getIdentityMethod.requiredCapabilities))
|
||||||
|
.build()
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
final response = result.parse<GetIdentityResponse>(
|
||||||
|
queryInvocation.methodCallId,
|
||||||
|
GetIdentityResponse.deserialize);
|
||||||
|
|
||||||
|
return IdentitiesResponse(identities: response?.list, state: response?.state);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
|
import 'package:tmail_ui_user/features/manage_account/data/datasource/manage_account_datasource.dart';
|
||||||
|
import 'package:tmail_ui_user/features/manage_account/domain/model/identities_response.dart';
|
||||||
|
import 'package:tmail_ui_user/features/manage_account/domain/repository/manage_account_repository.dart';
|
||||||
|
|
||||||
|
class ManageAccountRepositoryImpl extends ManageAccountRepository {
|
||||||
|
|
||||||
|
final ManageAccountDataSource dataSource;
|
||||||
|
|
||||||
|
ManageAccountRepositoryImpl(this.dataSource);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<IdentitiesResponse> getAllIdentities(AccountId accountId) {
|
||||||
|
return dataSource.getAllIdentities(accountId);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user