Files
TravelMate/lib/blocs/trip/trip_event.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

127 lines
4.2 KiB
Dart

/// Events for trip-related operations in the TripBloc.
///
/// This file defines all possible events that can be dispatched to the TripBloc
/// to trigger trip-related state changes and operations such as loading trips,
/// creating trips, updating trip information, and performing CRUD operations.
///
/// Event Categories:
/// - **Loading Events**: LoadTripsByUserId
/// - **CRUD Operations**: TripCreateRequested, TripUpdateRequested, TripDeleteRequested
/// - **State Management**: ResetTrips
///
/// The events support complete trip lifecycle management with automatic
/// list refreshing after operations to maintain UI consistency.
///
/// All events extend [TripEvent] and implement [Equatable] for proper
/// equality comparison in the BLoC pattern.
import 'package:equatable/equatable.dart';
import '../../models/trip.dart';
/// Base class for all trip-related events.
///
/// All trip events must extend this class and implement the [props] getter
/// for proper equality comparison in the BLoC pattern.
abstract class TripEvent extends Equatable {
const TripEvent();
@override
List<Object?> get props => [];
}
/// Event to load all trips associated with a specific user.
///
/// This event retrieves all trips where the user is a participant or organizer,
/// providing a comprehensive view of the user's travel activities. The loading
/// uses real-time streams to keep the trip list updated automatically.
///
/// Args:
/// [userId]: The unique identifier of the user whose trips should be loaded
class LoadTripsByUserId extends TripEvent {
/// The unique identifier of the user
final String userId;
/// Creates a LoadTripsByUserId event.
///
/// Args:
/// [userId]: The user ID to load trips for
const LoadTripsByUserId({required this.userId});
@override
List<Object?> get props => [userId];
}
/// Event to request creation of a new trip.
///
/// This event creates a new trip with the provided information and automatically
/// refreshes the user's trip list to show the newly created trip. The operation
/// includes validation and proper error handling.
///
/// Args:
/// [trip]: The trip object containing all the trip information to create
class TripCreateRequested extends TripEvent {
/// The trip object to create
final Trip trip;
/// Creates a TripCreateRequested event.
///
/// Args:
/// [trip]: The trip object to create
const TripCreateRequested({required this.trip});
@override
List<Object?> get props => [trip];
}
/// Event to request updating an existing trip.
///
/// This event updates an existing trip with new information and automatically
/// refreshes the user's trip list to reflect the changes. The trip must have
/// a valid ID for the update operation to succeed.
///
/// Args:
/// [trip]: The trip object with updated information (must include valid ID)
class TripUpdateRequested extends TripEvent {
/// The trip object with updated information
final Trip trip;
/// Creates a TripUpdateRequested event.
///
/// Args:
/// [trip]: The updated trip object (must have valid ID)
const TripUpdateRequested({required this.trip});
@override
List<Object?> get props => [trip];
}
/// Event to reset the trip state and clean up resources.
///
/// This event resets the TripBloc to its initial state, cancels any active
/// stream subscriptions, and clears the current user context. This is typically
/// used during user logout or when switching between different user contexts.
class ResetTrips extends TripEvent {
/// Creates a ResetTrips event.
const ResetTrips();
}
/// Event to request deletion of a trip.
///
/// This event permanently deletes a trip and all associated data including
/// groups, expenses, and messages. This is a destructive operation that cannot
/// be undone. The user's trip list is automatically refreshed after deletion.
///
/// Args:
/// [tripId]: The unique identifier of the trip to delete
class TripDeleteRequested extends TripEvent {
/// The unique identifier of the trip to delete
final String tripId;
/// Creates a TripDeleteRequested event.
///
/// Args:
/// [tripId]: The ID of the trip to delete
const TripDeleteRequested({required this.tripId});
@override
List<Object?> get props => [tripId];
}