Files
TravelMate/lib/models/group.dart
Dayron 2faf37f145 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.
2025-10-30 15:56:17 +01:00

94 lines
2.6 KiB
Dart

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,
required this.tripId,
required this.createdBy,
DateTime? createdAt,
DateTime? updatedAt,
List<GroupMember>? members,
}) : createdAt = createdAt ?? DateTime.now(),
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,
name: map['name'] ?? '',
tripId: map['tripId'] ?? '',
createdBy: map['createdBy'] ?? '',
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt'] ?? 0),
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updatedAt'] ?? 0),
members: [],
);
}
Map<String, dynamic> toMap() {
return {
'name': name,
'tripId': tripId,
'createdBy': createdBy,
'createdAt': createdAt.millisecondsSinceEpoch,
'updatedAt': updatedAt.millisecondsSinceEpoch,
};
}
Group copyWith({
String? id,
String? name,
String? tripId,
String? createdBy,
DateTime? createdAt,
DateTime? updatedAt,
List<GroupMember>? members,
}) {
return Group(
id: id ?? this.id,
name: name ?? this.name,
tripId: tripId ?? this.tripId,
createdBy: createdBy ?? this.createdBy,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
members: members ?? this.members,
);
}
}