TF-34 Add data layer login for fix bug mock data user

This commit is contained in:
dab246
2021-08-25 13:12:17 +07:00
committed by Dat H. Pham
parent b3e1534de3
commit cae1252fc8
16 changed files with 227 additions and 58 deletions
@@ -8,7 +8,7 @@ class AuthenticationRepositoryImpl extends AuthenticationRepository {
AuthenticationRepositoryImpl(this.loginDataSource);
@override
Future<User> authenticationUser(Uri baseUrl, UserName userName, Password password) {
Future<UserProfile> authenticationUser(Uri baseUrl, UserName userName, Password password) {
return loginDataSource.authenticationUser(baseUrl, userName, password);
}
}
@@ -1,6 +1,10 @@
import 'dart:convert';
import 'package:model/model.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tmail_ui_user/features/login/data/model/response/user_profile_response.dart';
import 'package:tmail_ui_user/features/login/data/utils/login_constant.dart';
import 'package:tmail_ui_user/features/login/data/extensions/user_profile_extension.dart';
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
class CredentialRepositoryImpl extends CredentialRepository {
@@ -53,4 +57,23 @@ class CredentialRepositoryImpl extends CredentialRepository {
Future saveUserName(UserName userName) async {
await sharedPreferences.setString(LoginConstant.keyUserName, userName.userName);
}
@override
Future<UserProfile> getUserProfile() async {
final json = sharedPreferences.getString(LoginConstant.keyUserProfile) ?? '';
Map<String, dynamic> mapObject = jsonDecode(json);
return UserProfileResponse.fromJson(mapObject).toUserProfile();
}
@override
Future removeUserProfile() async {
await sharedPreferences.remove(LoginConstant.keyUserProfile);
}
@override
Future saveUserProfile(UserProfile userProfile) async {
final userProfileResponse = userProfile.toUserProfileResponse();
final json = jsonEncode(userProfileResponse.toJson());
await sharedPreferences.setString(LoginConstant.keyUserProfile, json);
}
}