This commit is contained in:
Phuoc Nguyen
2025-10-10 18:06:40 +07:00
parent 77440ac957
commit 63e397d7e6
12 changed files with 1060 additions and 16 deletions

View File

@@ -89,21 +89,31 @@ class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
@override
Future<UserModel> getProfile() async {
try {
print('📡 DataSource: Calling getProfile API...');
final response = await dioClient.get(ApiConstants.profile);
print('📡 DataSource: Profile status=${response.statusCode}');
print('📡 DataSource: Profile response keys=${response.data?.keys?.toList()}');
print('📡 DataSource: Profile response=$response.data}');
if (response.statusCode == ApiConstants.statusOk) {
// API might return nested structure: {success, data: user, message}
// Check if response has 'data' key
final userData = response.data['data'] != null
? response.data['data'] as Map<String, dynamic>
: response.data as Map<String, dynamic>;
return UserModel.fromJson(userData);
// API returns nested structure: {success, data: user, message}
// Extract the 'data' object
final userData = response.data['data'] as Map<String, dynamic>;
print('📡 DataSource: Extracted user data with keys=${userData.keys.toList()}');
final userModel = UserModel.fromJson(userData);
print('📡 DataSource: User parsed successfully: ${userModel.name}');
return userModel;
} else {
throw ServerException('Get profile failed with status: ${response.statusCode}');
}
} on DioException catch (e) {
print('❌ DataSource: Profile DioException - ${e.message}');
throw _handleDioError(e);
} catch (e) {
} catch (e, stackTrace) {
print('❌ DataSource: Profile unexpected error - $e');
print('Stack trace: $stackTrace');
throw ServerException('Unexpected error getting profile: $e');
}
}