Refactoring - Version stable

This commit is contained in:
dahoud
2026-03-28 14:35:32 +00:00
parent d0e61ead97
commit 95d0e4502e
5 changed files with 141 additions and 17 deletions

View File

@@ -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) {