TF-886 Implement StoreAuthenticationInfo in repository and datasource

This commit is contained in:
dab246
2022-09-06 19:04:57 +07:00
committed by Dat H. Pham
parent 40d37fc37e
commit b95d294a3c
11 changed files with 76 additions and 15 deletions
@@ -0,0 +1,14 @@
import 'package:tmail_ui_user/features/caching/authentication_info_cache_client.dart';
import 'package:tmail_ui_user/features/login/data/model/authentication_info_cache.dart';
class AuthenticationInfoCacheManager {
final AuthenticationInfoCacheClient _authenticationInfoCacheClient;
AuthenticationInfoCacheManager(this._authenticationInfoCacheClient);
Future<void> storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache) {
return _authenticationInfoCacheClient.insertItem(
AuthenticationInfoCache.keyCacheValue,
authenticationInfoCache);
}
}
@@ -2,14 +2,20 @@ import 'dart:convert';
import 'package:model/model.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tmail_ui_user/features/login/data/local/authentication_info_cache_manager.dart';
import 'package:tmail_ui_user/features/login/data/model/authentication_info_cache.dart';
import 'package:tmail_ui_user/features/login/data/utils/login_constant.dart';
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
class CredentialRepositoryImpl extends CredentialRepository {
final SharedPreferences sharedPreferences;
final AuthenticationInfoCacheManager _authenticationInfoCacheManager;
CredentialRepositoryImpl(this.sharedPreferences);
CredentialRepositoryImpl(
this.sharedPreferences,
this._authenticationInfoCacheManager
);
@override
Future<Uri> getBaseUrl() async {
@@ -74,4 +80,9 @@ class CredentialRepositoryImpl extends CredentialRepository {
final json = jsonEncode(userProfileResponse.toJson());
await sharedPreferences.setString(LoginConstant.keyUserProfile, json);
}
@override
Future<void> storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache) {
return _authenticationInfoCacheManager.storeAuthenticationInfo(authenticationInfoCache);
}
}
@@ -1,6 +1,5 @@
class LoginConstant {
static const keyBaseUrl = 'KEY_BASE_URL';
static const keyUserName = 'KEY_USER_NAME';
static const keyPassword = 'KEY_PASSWORD';
static const keyUserProfile = 'KEY_USER_PROFILE';
static const String keyBaseUrl = 'KEY_BASE_URL';
static const String keyHiveEncrypt = 'KEY_HIVE_ENCRYPT';
}