Enhance model and service documentation with detailed comments and descriptions

- Updated Group, Trip, User, and other model classes to include comprehensive documentation for better understanding and maintainability.
- Improved error handling and logging in services, including AuthService, ErrorService, and StorageService.
- Added validation and business logic explanations in ExpenseService and TripService.
- Refactored method comments to follow a consistent format across the codebase.
- Translated error messages and comments from French to English for consistency.
This commit is contained in:
Dayron
2025-10-30 15:56:17 +01:00
parent 1eeea6997e
commit 2faf37f145
46 changed files with 2656 additions and 220 deletions

View File

@@ -3,29 +3,53 @@ import 'package:firebase_auth/firebase_auth.dart';
import 'package:travel_mate/services/error_service.dart';
import '../blocs/user/user_state.dart';
/// Service for managing user operations with Firestore and Firebase Auth.
///
/// This service provides functionality for user management including creating,
/// retrieving, updating, and deleting user data in Firestore. It also handles
/// user authentication state and provides methods for user profile management.
class UserService {
/// Error service for logging user operation errors.
final _errorService = ErrorService();
/// Firestore instance for database operations.
final FirebaseFirestore _firestore;
/// Firebase Auth instance for user authentication.
final FirebaseAuth _auth;
/// Collection name for users in Firestore.
static const String _usersCollection = 'users';
/// Creates a new [UserService] with optional Firestore and Auth instances.
///
/// If [firestore] or [auth] are not provided, the default instances will be used.
UserService({
FirebaseFirestore? firestore,
FirebaseAuth? auth,
}) : _firestore = firestore ?? FirebaseFirestore.instance,
_auth = auth ?? FirebaseAuth.instance;
// Obtenir l'utilisateur connecté actuel
/// Gets the currently authenticated Firebase user.
///
/// Returns the [User] object if authenticated, null otherwise.
User? getCurrentFirebaseUser() {
return _auth.currentUser;
}
// Obtenir l'ID de l'utilisateur connecté
/// Gets the ID of the currently authenticated user.
///
/// Returns the user ID string if authenticated, null otherwise.
String? getCurrentUserId() {
return _auth.currentUser?.uid;
}
// Créer un nouvel utilisateur dans Firestore
/// Creates a new user document in Firestore.
///
/// Takes a [UserModel] object and stores it in the users collection.
/// Returns true if successful, false if an error occurs.
///
/// [user] - The user model to create in Firestore
Future<bool> createUser(UserModel user) async {
try {
await _firestore
@@ -34,12 +58,16 @@ class UserService {
.set(user.toJson());
return true;
} catch (e) {
_errorService.logError('Erreur lors de la création de l\'utilisateur: $e', StackTrace.current);
_errorService.logError('Error creating user: $e', StackTrace.current);
return false;
}
}
// Obtenir un utilisateur par son ID
/// Retrieves a user by their ID from Firestore.
///
/// Returns a [UserModel] if the user exists, null otherwise.
///
/// [userId] - The ID of the user to retrieve
Future<UserModel?> getUserById(String userId) async {
try {
final doc = await _firestore