Version propre - Dashboard enhanced
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import '../models/membre_model.dart';
|
||||
import '../models/cotisation_model.dart';
|
||||
import '../models/wave_checkout_session_model.dart';
|
||||
import '../network/dio_client.dart';
|
||||
|
||||
@@ -164,6 +165,191 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// COTISATIONS
|
||||
// ========================================
|
||||
|
||||
/// Récupère la liste de toutes les cotisations avec pagination
|
||||
Future<List<CotisationModel>> getCotisations({int page = 0, int size = 20}) async {
|
||||
try {
|
||||
final response = await _dio.get('/api/cotisations', queryParameters: {
|
||||
'page': page,
|
||||
'size': size,
|
||||
});
|
||||
|
||||
if (response.data is List) {
|
||||
return (response.data as List)
|
||||
.map((json) => CotisationModel.fromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
throw Exception('Format de réponse invalide pour la liste des cotisations');
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la récupération des cotisations');
|
||||
}
|
||||
}
|
||||
|
||||
/// Récupère une cotisation par son ID
|
||||
Future<CotisationModel> getCotisationById(String id) async {
|
||||
try {
|
||||
final response = await _dio.get('/api/cotisations/$id');
|
||||
return CotisationModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la récupération de la cotisation');
|
||||
}
|
||||
}
|
||||
|
||||
/// Récupère une cotisation par son numéro de référence
|
||||
Future<CotisationModel> getCotisationByReference(String numeroReference) async {
|
||||
try {
|
||||
final response = await _dio.get('/api/cotisations/reference/$numeroReference');
|
||||
return CotisationModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la récupération de la cotisation');
|
||||
}
|
||||
}
|
||||
|
||||
/// Crée une nouvelle cotisation
|
||||
Future<CotisationModel> createCotisation(CotisationModel cotisation) async {
|
||||
try {
|
||||
final response = await _dio.post(
|
||||
'/api/cotisations',
|
||||
data: cotisation.toJson(),
|
||||
);
|
||||
return CotisationModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la création de la cotisation');
|
||||
}
|
||||
}
|
||||
|
||||
/// Met à jour une cotisation existante
|
||||
Future<CotisationModel> updateCotisation(String id, CotisationModel cotisation) async {
|
||||
try {
|
||||
final response = await _dio.put(
|
||||
'/api/cotisations/$id',
|
||||
data: cotisation.toJson(),
|
||||
);
|
||||
return CotisationModel.fromJson(response.data as Map<String, dynamic>);
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la mise à jour de la cotisation');
|
||||
}
|
||||
}
|
||||
|
||||
/// Supprime une cotisation
|
||||
Future<void> deleteCotisation(String id) async {
|
||||
try {
|
||||
await _dio.delete('/api/cotisations/$id');
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la suppression de la cotisation');
|
||||
}
|
||||
}
|
||||
|
||||
/// Récupère les cotisations d'un membre
|
||||
Future<List<CotisationModel>> getCotisationsByMembre(String membreId, {int page = 0, int size = 20}) async {
|
||||
try {
|
||||
final response = await _dio.get('/api/cotisations/membre/$membreId', queryParameters: {
|
||||
'page': page,
|
||||
'size': size,
|
||||
});
|
||||
|
||||
if (response.data is List) {
|
||||
return (response.data as List)
|
||||
.map((json) => CotisationModel.fromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
throw Exception('Format de réponse invalide pour les cotisations du membre');
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la récupération des cotisations du membre');
|
||||
}
|
||||
}
|
||||
|
||||
/// Récupère les cotisations par statut
|
||||
Future<List<CotisationModel>> getCotisationsByStatut(String statut, {int page = 0, int size = 20}) async {
|
||||
try {
|
||||
final response = await _dio.get('/api/cotisations/statut/$statut', queryParameters: {
|
||||
'page': page,
|
||||
'size': size,
|
||||
});
|
||||
|
||||
if (response.data is List) {
|
||||
return (response.data as List)
|
||||
.map((json) => CotisationModel.fromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
throw Exception('Format de réponse invalide pour les cotisations par statut');
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la récupération des cotisations par statut');
|
||||
}
|
||||
}
|
||||
|
||||
/// Récupère les cotisations en retard
|
||||
Future<List<CotisationModel>> getCotisationsEnRetard({int page = 0, int size = 20}) async {
|
||||
try {
|
||||
final response = await _dio.get('/api/cotisations/en-retard', queryParameters: {
|
||||
'page': page,
|
||||
'size': size,
|
||||
});
|
||||
|
||||
if (response.data is List) {
|
||||
return (response.data as List)
|
||||
.map((json) => CotisationModel.fromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
throw Exception('Format de réponse invalide pour les cotisations en retard');
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la récupération des cotisations en retard');
|
||||
}
|
||||
}
|
||||
|
||||
/// Recherche avancée de cotisations
|
||||
Future<List<CotisationModel>> rechercherCotisations({
|
||||
String? membreId,
|
||||
String? statut,
|
||||
String? typeCotisation,
|
||||
int? annee,
|
||||
int? mois,
|
||||
int page = 0,
|
||||
int size = 20,
|
||||
}) async {
|
||||
try {
|
||||
final queryParams = <String, dynamic>{
|
||||
'page': page,
|
||||
'size': size,
|
||||
};
|
||||
|
||||
if (membreId != null) queryParams['membreId'] = membreId;
|
||||
if (statut != null) queryParams['statut'] = statut;
|
||||
if (typeCotisation != null) queryParams['typeCotisation'] = typeCotisation;
|
||||
if (annee != null) queryParams['annee'] = annee;
|
||||
if (mois != null) queryParams['mois'] = mois;
|
||||
|
||||
final response = await _dio.get('/api/cotisations/recherche', queryParameters: queryParams);
|
||||
|
||||
if (response.data is List) {
|
||||
return (response.data as List)
|
||||
.map((json) => CotisationModel.fromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
throw Exception('Format de réponse invalide pour la recherche de cotisations');
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la recherche de cotisations');
|
||||
}
|
||||
}
|
||||
|
||||
/// Récupère les statistiques des cotisations
|
||||
Future<Map<String, dynamic>> getCotisationsStats() async {
|
||||
try {
|
||||
final response = await _dio.get('/api/cotisations/stats');
|
||||
return response.data as Map<String, dynamic>;
|
||||
} on DioException catch (e) {
|
||||
throw _handleDioException(e, 'Erreur lors de la récupération des statistiques des cotisations');
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// GESTION DES ERREURS
|
||||
// ========================================
|
||||
|
||||
Reference in New Issue
Block a user