Versione OK Pour l'onglet événements.

This commit is contained in:
DahoudG
2025-09-15 20:15:34 +00:00
parent 8a619ee1bf
commit 12d514d866
73 changed files with 11508 additions and 674 deletions

View File

@@ -1,15 +1,17 @@
import 'package:injectable/injectable.dart';
import '../../../../core/models/cotisation_model.dart';
import '../../../../core/services/api_service.dart';
import '../../../../core/services/cache_service.dart';
import '../../../cotisations/domain/repositories/cotisation_repository.dart';
/// Implémentation du repository des cotisations
/// Utilise ApiService pour communiquer avec le backend
/// Utilise ApiService pour communiquer avec le backend et CacheService pour le cache local
@LazySingleton(as: CotisationRepository)
class CotisationRepositoryImpl implements CotisationRepository {
final ApiService _apiService;
final CacheService _cacheService;
CotisationRepositoryImpl(this._apiService);
CotisationRepositoryImpl(this._apiService, this._cacheService);
@override
Future<List<CotisationModel>> getCotisations({int page = 0, int size = 20}) async {
@@ -79,6 +81,54 @@ class CotisationRepositoryImpl implements CotisationRepository {
@override
Future<Map<String, dynamic>> getCotisationsStats() async {
return await _apiService.getCotisationsStats();
// Essayer de récupérer depuis le cache d'abord
final cachedStats = await _cacheService.getCotisationsStats();
if (cachedStats != null) {
return cachedStats.toJson();
}
try {
final stats = await _apiService.getCotisationsStats();
// Sauvegarder en cache si possible
// Note: Conversion nécessaire selon la structure des stats du backend
// await _cacheService.saveCotisationsStats(statsModel);
return stats;
} catch (e) {
// En cas d'erreur, retourner le cache si disponible
if (cachedStats != null) {
return cachedStats.toJson();
}
rethrow;
}
}
/// Invalide tous les caches de listes de cotisations
Future<void> _invalidateListCaches() async {
// Nettoyer les caches de listes paginées
final keys = ['cotisations_page_0_size_20', 'cotisations_cache'];
for (final key in keys) {
await _cacheService.clearCotisations(key: key);
}
// Nettoyer le cache des statistiques
await _cacheService.clearCotisationsStats();
}
/// Force la synchronisation avec le serveur
Future<void> forceSync() async {
await _cacheService.clearAllCotisationsCache();
await _cacheService.updateLastSyncTimestamp();
}
/// Vérifie si une synchronisation est nécessaire
bool needsSync() {
return _cacheService.needsSync();
}
/// Retourne des informations sur le cache
Map<String, dynamic> getCacheInfo() {
return _cacheService.getCacheInfo();
}
}