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:
@@ -1,11 +1,27 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// Model representing a user in the travel mate application.
|
||||
///
|
||||
/// This class encapsulates user information including personal details
|
||||
/// and provides methods for serialization/deserialization with Firebase
|
||||
/// and JSON operations.
|
||||
class User {
|
||||
/// Unique identifier for the user (usually Firebase UID).
|
||||
final String? id;
|
||||
|
||||
/// User's last name.
|
||||
final String nom;
|
||||
|
||||
/// User's first name.
|
||||
final String prenom;
|
||||
|
||||
/// User's email address.
|
||||
final String email;
|
||||
|
||||
/// Creates a new [User] instance.
|
||||
///
|
||||
/// [nom], [prenom], and [email] are required fields.
|
||||
/// [id] is optional and typically assigned by Firebase.
|
||||
User({
|
||||
this.id,
|
||||
required this.nom,
|
||||
@@ -13,7 +29,9 @@ class User {
|
||||
required this.email,
|
||||
});
|
||||
|
||||
// Constructeur pour créer un User depuis un Map (utile pour Firebase)
|
||||
/// Creates a [User] instance from a Map (useful for Firebase operations).
|
||||
///
|
||||
/// Handles null values gracefully by providing empty string defaults.
|
||||
factory User.fromMap(Map<String, dynamic> map) {
|
||||
return User(
|
||||
id: map['id'],
|
||||
@@ -23,13 +41,17 @@ class User {
|
||||
);
|
||||
}
|
||||
|
||||
// Constructeur pour créer un User depuis JSON
|
||||
/// Creates a [User] instance from a JSON string.
|
||||
///
|
||||
/// Parses the JSON and delegates to [fromMap] for object creation.
|
||||
factory User.fromJson(String jsonStr) {
|
||||
Map<String, dynamic> map = json.decode(jsonStr);
|
||||
return User.fromMap(map);
|
||||
}
|
||||
|
||||
// Méthode pour convertir un User en Map (utile pour Firebase)
|
||||
/// Converts the [User] instance to a Map (useful for Firebase operations).
|
||||
///
|
||||
/// Returns a map with all user properties for database storage.
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
@@ -39,15 +61,20 @@ class User {
|
||||
};
|
||||
}
|
||||
|
||||
// Méthode pour convertir un User en JSON
|
||||
/// Converts the [User] instance to a JSON string.
|
||||
///
|
||||
/// Useful for API communications and data serialization.
|
||||
String toJson() {
|
||||
return json.encode(toMap());
|
||||
}
|
||||
|
||||
// Méthode pour obtenir le nom complet
|
||||
/// Gets the user's full name in "first last" format.
|
||||
String get fullName => '$prenom $nom';
|
||||
|
||||
// Méthode pour créer une copie avec des modifications
|
||||
/// Creates a copy of this user with optionally modified properties.
|
||||
///
|
||||
/// Allows updating specific fields while preserving others.
|
||||
/// Useful for state management and partial updates.
|
||||
User copyWith({
|
||||
String? id,
|
||||
String? nom,
|
||||
@@ -62,17 +89,22 @@ class User {
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns a string representation of the user.
|
||||
@override
|
||||
String toString() {
|
||||
return 'User(id: $id, nom: $nom, prenom: $prenom, email: $email)';
|
||||
}
|
||||
|
||||
/// Compares users based on email address.
|
||||
///
|
||||
/// Two users are considered equal if they have the same email.
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
return other is User && other.email == email;
|
||||
}
|
||||
|
||||
/// Hash code based on email address.
|
||||
@override
|
||||
int get hashCode => email.hashCode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user