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,47 +3,109 @@ import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'expense_split.dart';
/// Enumeration of supported currencies for expenses.
///
/// Each currency includes both a display symbol and standard currency code.
enum ExpenseCurrency {
/// Euro currency
eur('', 'EUR'),
/// US Dollar currency
usd('\$', 'USD'),
/// British Pound currency
gbp('£', 'GBP');
const ExpenseCurrency(this.symbol, this.code);
/// Currency symbol for display (e.g., €, $, £)
final String symbol;
/// Standard currency code (e.g., EUR, USD, GBP)
final String code;
}
/// Enumeration of expense categories with display names and icons.
///
/// Provides predefined categories for organizing travel expenses.
enum ExpenseCategory {
/// Restaurant and food expenses
restaurant('Restaurant', Icons.restaurant),
/// Transportation expenses
transport('Transport', Icons.directions_car),
accommodation('Hébergement', Icons.hotel),
entertainment('Loisirs', Icons.local_activity),
/// Accommodation and lodging expenses
accommodation('Accommodation', Icons.hotel),
/// Entertainment and activity expenses
entertainment('Entertainment', Icons.local_activity),
/// Shopping expenses
shopping('Shopping', Icons.shopping_bag),
other('Autre', Icons.category);
/// Other miscellaneous expenses
other('Other', Icons.category);
const ExpenseCategory(this.displayName, this.icon);
/// Human-readable display name for the category
final String displayName;
/// Icon representing the category
final IconData icon;
}
/// Model representing a travel expense.
///
/// This class encapsulates all information about an expense including
/// amount, currency, category, who paid, how it's split among participants,
/// and receipt information. It extends [Equatable] for value comparison.
class Expense extends Equatable {
/// Unique identifier for the expense
final String id;
/// ID of the group this expense belongs to
final String groupId;
/// Description of the expense
final String description;
/// Amount of the expense in the original currency
final double amount;
/// Currency of the expense
final ExpenseCurrency currency;
final double amountInEur; // Montant converti en EUR
/// Amount converted to EUR for standardized calculations
final double amountInEur;
/// Category of the expense
final ExpenseCategory category;
/// ID of the user who paid for this expense
final String paidById;
/// Name of the user who paid for this expense
final String paidByName;
/// Date when the expense occurred
final DateTime date;
/// Timestamp when the expense was created
final DateTime createdAt;
/// Timestamp when the expense was last edited (null if never edited)
final DateTime? editedAt;
/// Whether this expense has been edited after creation
final bool isEdited;
/// Whether this expense has been archived
final bool isArchived;
/// URL to the receipt image (optional)
final String? receiptUrl;
/// List of expense splits showing how the cost is divided
final List<ExpenseSplit> splits;
/// Creates a new [Expense] instance.
///
/// All parameters except [editedAt] and [receiptUrl] are required.
const Expense({
required this.id,
required this.groupId,

View File

@@ -1,14 +1,37 @@
import 'group_member.dart';
/// Model representing a travel group.
///
/// A group is a collection of travelers who are part of a specific trip.
/// It contains information about group members, creation details, and
/// provides methods for serialization with Firestore.
class Group {
/// Unique identifier for the group
final String id;
/// Display name of the group
final String name;
/// ID of the trip this group belongs to
final String tripId;
/// ID of the user who created this group
final String createdBy;
/// Timestamp when the group was created
final DateTime createdAt;
/// Timestamp when the group was last updated
final DateTime updatedAt;
/// List of members in this group
final List<GroupMember> members;
/// Creates a new [Group] instance.
///
/// [id], [name], [tripId], and [createdBy] are required.
/// [createdAt] and [updatedAt] default to current time if not provided.
/// [members] defaults to empty list if not provided.
Group({
required this.id,
required this.name,
@@ -21,6 +44,12 @@ class Group {
updatedAt = updatedAt ?? DateTime.now(),
members = members ?? [];
/// Creates a [Group] instance from a Firestore document map.
///
/// [map] - The document data from Firestore
/// [id] - The document ID from Firestore
///
/// Returns a new [Group] instance with data from the map.
factory Group.fromMap(Map<String, dynamic> map, String id) {
return Group(
id: id,

View File

@@ -1,20 +1,52 @@
import 'dart:convert';
import 'package:cloud_firestore/cloud_firestore.dart';
/// Model representing a travel trip in the application.
///
/// This class encapsulates all trip-related information including dates,
/// location, participants, and budget details. It provides serialization
/// methods for Firebase operations and supports trip lifecycle management.
class Trip {
/// Unique identifier for the trip (usually Firestore document ID).
final String? id;
/// Title or name of the trip.
final String title;
/// Detailed description of the trip.
final String description;
/// Trip destination or location.
final String location;
/// Trip start date and time.
final DateTime startDate;
/// Trip end date and time.
final DateTime endDate;
/// Optional budget for the trip in the local currency.
final double? budget;
/// List of participant user IDs.
final List<String> participants;
/// User ID of the trip creator.
final String createdBy;
/// Timestamp when the trip was created.
final DateTime createdAt;
/// Timestamp when the trip was last updated.
final DateTime updatedAt;
/// Current status of the trip (e.g., 'draft', 'active', 'completed').
final String status;
/// Creates a new [Trip] instance.
///
/// Most fields are required except [id] and [budget].
/// [status] defaults to 'draft' for new trips.
Trip({
this.id,
required this.title,

View File

@@ -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;
}