update info

This commit is contained in:
Phuoc Nguyen
2025-11-20 10:12:24 +07:00
parent 54cb7d0fdd
commit 0708ed7d6f
17 changed files with 2144 additions and 161 deletions

View File

@@ -0,0 +1,101 @@
/// User Info Repository Implementation
///
/// Implements the UserInfoRepository interface with API integration.
library;
import 'package:worker/core/errors/exceptions.dart';
import 'package:worker/features/account/data/datasources/user_info_remote_datasource.dart';
import 'package:worker/features/account/domain/entities/user_info.dart';
import 'package:worker/features/account/domain/repositories/user_info_repository.dart';
/// User Info Repository Implementation
///
/// Handles user information operations with:
/// - API data fetching via remote datasource
/// - Error handling and transformation
/// - Entity conversion
class UserInfoRepositoryImpl implements UserInfoRepository {
UserInfoRepositoryImpl({
required this.remoteDataSource,
});
final UserInfoRemoteDataSource remoteDataSource;
// =========================================================================
// GET USER INFO
// =========================================================================
@override
Future<UserInfo> getUserInfo() async {
try {
_debugPrint('Fetching user info from API');
// Fetch from remote datasource
final userInfoModel = await remoteDataSource.getUserInfo();
_debugPrint('Successfully fetched user info: ${userInfoModel.fullName}');
// Convert model to entity
return userInfoModel.toEntity();
} on UnauthorizedException catch (e) {
_debugPrint('Unauthorized error: $e');
rethrow;
} on NotFoundException catch (e) {
_debugPrint('Not found error: $e');
rethrow;
} on ServerException catch (e) {
_debugPrint('Server error: $e');
rethrow;
} on NetworkException catch (e) {
_debugPrint('Network error: $e');
rethrow;
} catch (e) {
_debugPrint('Unexpected error: $e');
throw ServerException('Failed to get user info: $e');
}
}
// =========================================================================
// REFRESH USER INFO
// =========================================================================
@override
Future<UserInfo> refreshUserInfo() async {
try {
_debugPrint('Refreshing user info from API');
// Fetch fresh data from remote datasource
final userInfoModel = await remoteDataSource.refreshUserInfo();
_debugPrint('Successfully refreshed user info: ${userInfoModel.fullName}');
// Convert model to entity
return userInfoModel.toEntity();
} on UnauthorizedException catch (e) {
_debugPrint('Unauthorized error on refresh: $e');
rethrow;
} on NotFoundException catch (e) {
_debugPrint('Not found error on refresh: $e');
rethrow;
} on ServerException catch (e) {
_debugPrint('Server error on refresh: $e');
rethrow;
} on NetworkException catch (e) {
_debugPrint('Network error on refresh: $e');
rethrow;
} catch (e) {
_debugPrint('Unexpected error on refresh: $e');
throw ServerException('Failed to refresh user info: $e');
}
}
}
// ============================================================================
// DEBUG UTILITIES
// ============================================================================
/// Debug print helper
void _debugPrint(String message) {
// ignore: avoid_print
print('[UserInfoRepository] $message');
}