Authentification stable - WIP
This commit is contained in:
@@ -1,134 +0,0 @@
|
||||
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 et CacheService pour le cache local
|
||||
@LazySingleton(as: CotisationRepository)
|
||||
class CotisationRepositoryImpl implements CotisationRepository {
|
||||
final ApiService _apiService;
|
||||
final CacheService _cacheService;
|
||||
|
||||
CotisationRepositoryImpl(this._apiService, this._cacheService);
|
||||
|
||||
@override
|
||||
Future<List<CotisationModel>> getCotisations({int page = 0, int size = 20}) async {
|
||||
return await _apiService.getCotisations(page: page, size: size);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<CotisationModel> getCotisationById(String id) async {
|
||||
return await _apiService.getCotisationById(id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<CotisationModel> getCotisationByReference(String numeroReference) async {
|
||||
return await _apiService.getCotisationByReference(numeroReference);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<CotisationModel> createCotisation(CotisationModel cotisation) async {
|
||||
return await _apiService.createCotisation(cotisation);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<CotisationModel> updateCotisation(String id, CotisationModel cotisation) async {
|
||||
return await _apiService.updateCotisation(id, cotisation);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteCotisation(String id) async {
|
||||
return await _apiService.deleteCotisation(id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<CotisationModel>> getCotisationsByMembre(String membreId, {int page = 0, int size = 20}) async {
|
||||
return await _apiService.getCotisationsByMembre(membreId, page: page, size: size);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<CotisationModel>> getCotisationsByStatut(String statut, {int page = 0, int size = 20}) async {
|
||||
return await _apiService.getCotisationsByStatut(statut, page: page, size: size);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<CotisationModel>> getCotisationsEnRetard({int page = 0, int size = 20}) async {
|
||||
return await _apiService.getCotisationsEnRetard(page: page, size: size);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<CotisationModel>> rechercherCotisations({
|
||||
String? membreId,
|
||||
String? statut,
|
||||
String? typeCotisation,
|
||||
int? annee,
|
||||
int? mois,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
return await _apiService.rechercherCotisations(
|
||||
membreId: membreId,
|
||||
statut: statut,
|
||||
typeCotisation: typeCotisation,
|
||||
annee: annee,
|
||||
mois: mois,
|
||||
page: page,
|
||||
size: size,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> getCotisationsStats() async {
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user