Refactoring - Version stable
This commit is contained in:
@@ -64,6 +64,9 @@ class DashboardRemoteDataSourceImpl implements DashboardRemoteDataSource {
|
||||
throw ServerException('Failed to load member dashboard: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
throw const NotFoundException('Profil membre non trouvé');
|
||||
}
|
||||
AppLogger.error('DashboardRemoteDataSource: getMemberDashboardData', error: e);
|
||||
throw ServerException('Network error: ${e.message}');
|
||||
} catch (e, st) {
|
||||
@@ -102,6 +105,9 @@ class DashboardRemoteDataSourceImpl implements DashboardRemoteDataSource {
|
||||
throw ServerException('Failed to load adherent account: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
throw const NotFoundException('Compte adhérent non trouvé');
|
||||
}
|
||||
AppLogger.error('DashboardRemoteDataSource: getCompteAdherent', error: e);
|
||||
throw ServerException('Network error: ${e.message}');
|
||||
} catch (e, st) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../models/membre_dashboard_synthese_model.dart';
|
||||
import '../models/compte_adherent_model.dart';
|
||||
import '../../../../core/error/exceptions.dart';
|
||||
import '../../../../core/error/failures.dart';
|
||||
import '../../../../core/utils/logger.dart';
|
||||
import '../../../../core/network/network_info.dart';
|
||||
|
||||
@LazySingleton(as: DashboardRepository)
|
||||
@@ -29,6 +30,13 @@ class DashboardRepositoryImpl implements DashboardRepository {
|
||||
try {
|
||||
final model = await remoteDataSource.getCompteAdherent();
|
||||
return Right(_mapCompteToEntity(model));
|
||||
} on NotFoundException {
|
||||
return const Left(NotFoundFailure(
|
||||
'Compte adhérent non trouvé',
|
||||
null,
|
||||
false,
|
||||
'Votre profil membre est en cours de création.',
|
||||
));
|
||||
} on ServerException catch (e) {
|
||||
return Left(ServerFailure(e.message));
|
||||
} catch (e) {
|
||||
@@ -49,13 +57,26 @@ class DashboardRepositoryImpl implements DashboardRepository {
|
||||
final useMemberDashboard = organizationId.trim().isEmpty;
|
||||
if (useMemberDashboard) {
|
||||
// Chargement parallèle de la synthèse et du compte adhérent unifié
|
||||
final results = await Future.wait([
|
||||
remoteDataSource.getMemberDashboardData(),
|
||||
remoteDataSource.getCompteAdherent(),
|
||||
]);
|
||||
|
||||
final synthese = results[0] as MembreDashboardSyntheseModel;
|
||||
final compteModel = results[1] as CompteAdherentModel;
|
||||
MembreDashboardSyntheseModel? synthese;
|
||||
CompteAdherentModel? compteModel;
|
||||
|
||||
try {
|
||||
final results = await Future.wait([
|
||||
remoteDataSource.getMemberDashboardData(),
|
||||
remoteDataSource.getCompteAdherent(),
|
||||
]);
|
||||
synthese = results[0] as MembreDashboardSyntheseModel;
|
||||
compteModel = results[1] as CompteAdherentModel;
|
||||
} on NotFoundException {
|
||||
// Le membre existe dans Keycloak mais pas encore en base → état intermédiaire
|
||||
AppLogger.info('DashboardRepository: membre non encore enregistré en base');
|
||||
return const Left(NotFoundFailure(
|
||||
'Profil membre non trouvé',
|
||||
null,
|
||||
false,
|
||||
'Votre profil membre est en cours de création.',
|
||||
));
|
||||
}
|
||||
|
||||
// Fallback : si les montants sont à zéro mais qu'il y a des cotisations,
|
||||
// on complète avec /api/cotisations/mes-cotisations/synthese
|
||||
@@ -67,8 +88,8 @@ class DashboardRepositoryImpl implements DashboardRepository {
|
||||
}
|
||||
|
||||
return Right(_mapMemberSyntheseToEntity(
|
||||
synthese,
|
||||
userId,
|
||||
synthese,
|
||||
userId,
|
||||
cotSynthese: cotSynthese,
|
||||
compteModel: compteModel,
|
||||
));
|
||||
@@ -76,6 +97,13 @@ class DashboardRepositoryImpl implements DashboardRepository {
|
||||
|
||||
final dashboardData = await remoteDataSource.getDashboardData(organizationId, userId);
|
||||
return Right(_mapToEntity(dashboardData));
|
||||
} on NotFoundException {
|
||||
return const Left(NotFoundFailure(
|
||||
'Profil membre non trouvé',
|
||||
null,
|
||||
false,
|
||||
'Votre profil membre est en cours de création.',
|
||||
));
|
||||
} on ServerException catch (e) {
|
||||
return Left(ServerFailure(e.message));
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user