feat: Add logger service and improve expense dialog with enhanced receipt management and calculation logic.
This commit is contained in:
@@ -16,7 +16,10 @@ class ActivityRepository {
|
||||
/// Ajoute une nouvelle activité
|
||||
Future<String?> addActivity(Activity activity) async {
|
||||
try {
|
||||
print('ActivityRepository: Ajout d\'une activité: ${activity.name}');
|
||||
_errorService.logInfo(
|
||||
'ActivityRepository',
|
||||
'Ajout d\'une activité: ${activity.name}',
|
||||
);
|
||||
|
||||
final docRef = await _firestore
|
||||
.collection(_collection)
|
||||
@@ -25,10 +28,16 @@ class ActivityRepository {
|
||||
// Mettre à jour l'activité avec l'ID généré
|
||||
await docRef.update({'id': docRef.id});
|
||||
|
||||
print('ActivityRepository: Activité ajoutée avec ID: ${docRef.id}');
|
||||
_errorService.logSuccess(
|
||||
'ActivityRepository',
|
||||
'Activité ajoutée avec ID: ${docRef.id}',
|
||||
);
|
||||
return docRef.id;
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur lors de l\'ajout: $e');
|
||||
_errorService.logError(
|
||||
'ActivityRepository',
|
||||
'Erreur lors de l\'ajout: $e',
|
||||
);
|
||||
_errorService.logError(
|
||||
'activity_repository',
|
||||
'Erreur ajout activité: $e',
|
||||
@@ -40,8 +49,9 @@ class ActivityRepository {
|
||||
/// Récupère toutes les activités d'un voyage
|
||||
Future<List<Activity>> getActivitiesByTrip(String tripId) async {
|
||||
try {
|
||||
print(
|
||||
'ActivityRepository: Récupération des activités pour le voyage: $tripId',
|
||||
_errorService.logInfo(
|
||||
'ActivityRepository',
|
||||
'Récupération des activités pour le voyage: $tripId',
|
||||
);
|
||||
|
||||
// Modifié pour éviter l'erreur d'index composite
|
||||
@@ -58,10 +68,16 @@ class ActivityRepository {
|
||||
// Tri en mémoire par date de mise à jour (plus récent en premier)
|
||||
activities.sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
|
||||
|
||||
print('ActivityRepository: ${activities.length} activités trouvées');
|
||||
_errorService.logInfo(
|
||||
'ActivityRepository',
|
||||
'${activities.length} activités trouvées',
|
||||
);
|
||||
return activities;
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur lors de la récupération: $e');
|
||||
_errorService.logError(
|
||||
'ActivityRepository',
|
||||
'Erreur lors de la récupération: $e',
|
||||
);
|
||||
_errorService.logError(
|
||||
'activity_repository',
|
||||
'Erreur récupération activités: $e',
|
||||
@@ -89,7 +105,10 @@ class ActivityRepository {
|
||||
|
||||
return null;
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur récupération activité: $e');
|
||||
_errorService.logError(
|
||||
'ActivityRepository',
|
||||
'Erreur récupération activité: $e',
|
||||
);
|
||||
_errorService.logError(
|
||||
'activity_repository',
|
||||
'Erreur récupération activité: $e',
|
||||
@@ -101,17 +120,26 @@ class ActivityRepository {
|
||||
/// Met à jour une activité
|
||||
Future<bool> updateActivity(Activity activity) async {
|
||||
try {
|
||||
print('ActivityRepository: Mise à jour de l\'activité: ${activity.id}');
|
||||
_errorService.logInfo(
|
||||
'ActivityRepository',
|
||||
'Mise à jour de l\'activité: ${activity.id}',
|
||||
);
|
||||
|
||||
await _firestore
|
||||
.collection(_collection)
|
||||
.doc(activity.id)
|
||||
.update(activity.copyWith(updatedAt: DateTime.now()).toMap());
|
||||
|
||||
print('ActivityRepository: Activité mise à jour avec succès');
|
||||
_errorService.logSuccess(
|
||||
'ActivityRepository',
|
||||
'Activité mise à jour avec succès',
|
||||
);
|
||||
return true;
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur lors de la mise à jour: $e');
|
||||
_errorService.logError(
|
||||
'ActivityRepository',
|
||||
'Erreur lors de la mise à jour: $e',
|
||||
);
|
||||
_errorService.logError(
|
||||
'activity_repository',
|
||||
'Erreur mise à jour activité: $e',
|
||||
@@ -123,14 +151,23 @@ class ActivityRepository {
|
||||
/// Supprime une activité
|
||||
Future<bool> deleteActivity(String activityId) async {
|
||||
try {
|
||||
print('ActivityRepository: Suppression de l\'activité: $activityId');
|
||||
_errorService.logInfo(
|
||||
'ActivityRepository',
|
||||
'Suppression de l\'activité: $activityId',
|
||||
);
|
||||
|
||||
await _firestore.collection(_collection).doc(activityId).delete();
|
||||
|
||||
print('ActivityRepository: Activité supprimée avec succès');
|
||||
_errorService.logSuccess(
|
||||
'ActivityRepository',
|
||||
'Activité supprimée avec succès',
|
||||
);
|
||||
return true;
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur lors de la suppression: $e');
|
||||
_errorService.logError(
|
||||
'ActivityRepository',
|
||||
'Erreur lors de la suppression: $e',
|
||||
);
|
||||
_errorService.logError(
|
||||
'activity_repository',
|
||||
'Erreur suppression activité: $e',
|
||||
@@ -148,7 +185,7 @@ class ActivityRepository {
|
||||
try {
|
||||
// Validation des paramètres
|
||||
if (activityId.isEmpty) {
|
||||
print('ActivityRepository: ID d\'activité vide');
|
||||
_errorService.logError('ActivityRepository', 'ID d\'activité vide');
|
||||
_errorService.logError(
|
||||
'activity_repository',
|
||||
'ID d\'activité vide pour le vote',
|
||||
@@ -157,7 +194,7 @@ class ActivityRepository {
|
||||
}
|
||||
|
||||
if (userId.isEmpty) {
|
||||
print('ActivityRepository: ID d\'utilisateur vide');
|
||||
_errorService.logError('ActivityRepository', 'ID d\'utilisateur vide');
|
||||
_errorService.logError(
|
||||
'activity_repository',
|
||||
'ID d\'utilisateur vide pour le vote',
|
||||
@@ -165,7 +202,10 @@ class ActivityRepository {
|
||||
return false;
|
||||
}
|
||||
|
||||
print('ActivityRepository: Vote pour l\'activité $activityId: $vote');
|
||||
_errorService.logInfo(
|
||||
'ActivityRepository',
|
||||
'Vote pour l\'activité $activityId: $vote',
|
||||
);
|
||||
|
||||
// vote: 1 pour positif, -1 pour négatif, 0 pour supprimer le vote
|
||||
final activityRef = _firestore.collection(_collection).doc(activityId);
|
||||
@@ -194,10 +234,13 @@ class ActivityRepository {
|
||||
});
|
||||
});
|
||||
|
||||
print('ActivityRepository: Vote enregistré avec succès');
|
||||
_errorService.logSuccess(
|
||||
'ActivityRepository',
|
||||
'Vote enregistré avec succès',
|
||||
);
|
||||
return true;
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur lors du vote: $e');
|
||||
_errorService.logError('ActivityRepository', 'Erreur lors du vote: $e');
|
||||
_errorService.logError('activity_repository', 'Erreur vote: $e');
|
||||
return false;
|
||||
}
|
||||
@@ -221,7 +264,10 @@ class ActivityRepository {
|
||||
return activities;
|
||||
});
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur stream activités: $e');
|
||||
_errorService.logError(
|
||||
'ActivityRepository',
|
||||
'Erreur stream activités: $e',
|
||||
);
|
||||
_errorService.logError(
|
||||
'activity_repository',
|
||||
'Erreur stream activités: $e',
|
||||
@@ -233,8 +279,9 @@ class ActivityRepository {
|
||||
/// Ajoute plusieurs activités en lot
|
||||
Future<List<String>> addActivitiesBatch(List<Activity> activities) async {
|
||||
try {
|
||||
print(
|
||||
'ActivityRepository: Ajout en lot de ${activities.length} activités',
|
||||
_errorService.logInfo(
|
||||
'ActivityRepository',
|
||||
'Ajout en lot de ${activities.length} activités',
|
||||
);
|
||||
|
||||
final batch = _firestore.batch();
|
||||
@@ -249,10 +296,13 @@ class ActivityRepository {
|
||||
|
||||
await batch.commit();
|
||||
|
||||
print('ActivityRepository: ${addedIds.length} activités ajoutées en lot');
|
||||
_errorService.logSuccess(
|
||||
'ActivityRepository',
|
||||
'${addedIds.length} activités ajoutées en lot',
|
||||
);
|
||||
return addedIds;
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur ajout en lot: $e');
|
||||
_errorService.logError('ActivityRepository', 'Erreur ajout en lot: $e');
|
||||
_errorService.logError('activity_repository', 'Erreur ajout en lot: $e');
|
||||
return [];
|
||||
}
|
||||
@@ -264,8 +314,9 @@ class ActivityRepository {
|
||||
String category,
|
||||
) async {
|
||||
try {
|
||||
print(
|
||||
'ActivityRepository: Recherche par catégorie: $category pour le voyage: $tripId',
|
||||
_errorService.logInfo(
|
||||
'ActivityRepository',
|
||||
'Recherche par catégorie: $category pour le voyage: $tripId',
|
||||
);
|
||||
|
||||
// Récupérer toutes les activités du voyage puis filtrer en mémoire
|
||||
@@ -284,7 +335,10 @@ class ActivityRepository {
|
||||
|
||||
return activities;
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur recherche par catégorie: $e');
|
||||
_errorService.logError(
|
||||
'ActivityRepository',
|
||||
'Erreur recherche par catégorie: $e',
|
||||
);
|
||||
_errorService.logError(
|
||||
'activity_repository',
|
||||
'Erreur recherche par catégorie: $e',
|
||||
@@ -315,7 +369,10 @@ class ActivityRepository {
|
||||
|
||||
return activities.take(limit).toList();
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur activités top rated: $e');
|
||||
_errorService.logError(
|
||||
'ActivityRepository',
|
||||
'Erreur activités top rated: $e',
|
||||
);
|
||||
_errorService.logError('activity_repository', 'Erreur top rated: $e');
|
||||
return [];
|
||||
}
|
||||
@@ -337,7 +394,10 @@ class ActivityRepository {
|
||||
|
||||
return null;
|
||||
} catch (e) {
|
||||
print('ActivityRepository: Erreur recherche activité existante: $e');
|
||||
_errorService.logError(
|
||||
'ActivityRepository',
|
||||
'Erreur recherche activité existante: $e',
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,10 +117,16 @@ class GroupRepository {
|
||||
|
||||
if (memberIds.isNotEmpty) {
|
||||
await _groupsCollection.doc(groupId).update({'memberIds': memberIds});
|
||||
print('Migration réussie pour le groupe $groupId');
|
||||
_errorService.logSuccess(
|
||||
'GroupRepository',
|
||||
'Migration réussie pour le groupe $groupId',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Erreur de migration pour le groupe $groupId: $e');
|
||||
_errorService.logError(
|
||||
'GroupRepository',
|
||||
'Erreur de migration pour le groupe $groupId: $e',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user