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,38 @@
|
||||
/// Business Logic Component for managing authentication state.
|
||||
///
|
||||
/// The [AuthBloc] handles authentication-related events and manages the
|
||||
/// authentication state throughout the application. It coordinates with
|
||||
/// the [AuthRepository] to perform authentication operations and emits
|
||||
/// appropriate states based on the results.
|
||||
///
|
||||
/// Supported authentication methods:
|
||||
/// - Email and password authentication
|
||||
/// - Google Sign-In
|
||||
/// - Apple Sign-In
|
||||
/// - Password reset functionality
|
||||
///
|
||||
/// This bloc handles the following events:
|
||||
/// - [AuthCheckRequested]: Verifies current authentication status
|
||||
/// - [AuthSignInRequested]: Processes email/password sign-in
|
||||
/// - [AuthSignUpRequested]: Processes user registration
|
||||
/// - [AuthGoogleSignInRequested]: Processes Google authentication
|
||||
/// - [AuthAppleSignInRequested]: Processes Apple authentication
|
||||
/// - [AuthSignOutRequested]: Processes user sign-out
|
||||
/// - [AuthPasswordResetRequested]: Processes password reset requests
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../repositories/auth_repository.dart';
|
||||
import 'auth_event.dart';
|
||||
import 'auth_state.dart';
|
||||
|
||||
/// BLoC for managing authentication state and operations.
|
||||
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
/// Repository for authentication operations.
|
||||
final AuthRepository _authRepository;
|
||||
|
||||
/// Creates an [AuthBloc] with the provided [authRepository].
|
||||
///
|
||||
/// The bloc starts in the [AuthInitial] state and registers event handlers
|
||||
/// for all supported authentication events.
|
||||
AuthBloc({required AuthRepository authRepository})
|
||||
: _authRepository = authRepository,
|
||||
super(AuthInitial()) {
|
||||
@@ -18,6 +45,10 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
on<AuthPasswordResetRequested>(_onPasswordResetRequested);
|
||||
}
|
||||
|
||||
/// Handles [AuthCheckRequested] events.
|
||||
///
|
||||
/// Checks if a user is currently authenticated and emits the appropriate state.
|
||||
/// If a user is found, attempts to fetch user data from Firestore.
|
||||
Future<void> _onAuthCheckRequested(
|
||||
AuthCheckRequested event,
|
||||
Emitter<AuthState> emit,
|
||||
@@ -28,7 +59,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
final currentUser = _authRepository.currentUser;
|
||||
|
||||
if (currentUser != null) {
|
||||
// Récupérer les données utilisateur depuis Firestore
|
||||
// Fetch user data from Firestore
|
||||
final user = await _authRepository.getUserFromFirestore(currentUser.uid);
|
||||
|
||||
if (user != null) {
|
||||
@@ -44,6 +75,10 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles [AuthSignInRequested] events.
|
||||
///
|
||||
/// Attempts to sign in a user with the provided email and password.
|
||||
/// Emits [AuthAuthenticated] on success or [AuthError] on failure.
|
||||
Future<void> _onSignInRequested(
|
||||
AuthSignInRequested event,
|
||||
Emitter<AuthState> emit,
|
||||
@@ -59,13 +94,17 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
if (user != null) {
|
||||
emit(AuthAuthenticated(user: user));
|
||||
} else {
|
||||
emit(const AuthError(message: 'Email ou mot de passe incorrect'));
|
||||
emit(const AuthError(message: 'Invalid email or password'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(AuthError(message: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles [AuthSignUpRequested] events.
|
||||
///
|
||||
/// Attempts to create a new user account with the provided information.
|
||||
/// Emits [AuthAuthenticated] on success or [AuthError] on failure.
|
||||
Future<void> _onSignUpRequested(
|
||||
AuthSignUpRequested event,
|
||||
Emitter<AuthState> emit,
|
||||
@@ -83,13 +122,17 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
if (user != null) {
|
||||
emit(AuthAuthenticated(user: user));
|
||||
} else {
|
||||
emit(const AuthError(message: 'Erreur lors de l\'inscription'));
|
||||
emit(const AuthError(message: 'Registration failed'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(AuthError(message: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles [AuthGoogleSignInRequested] events.
|
||||
///
|
||||
/// Attempts to sign in the user using Google authentication.
|
||||
/// Emits [AuthAuthenticated] on success or [AuthError] on failure.
|
||||
Future<void> _onGoogleSignInRequested(
|
||||
AuthGoogleSignInRequested event,
|
||||
Emitter<AuthState> emit,
|
||||
@@ -102,13 +145,17 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
if (user != null) {
|
||||
emit(AuthAuthenticated(user: user));
|
||||
} else {
|
||||
emit(const AuthError(message: 'Connexion Google annulée'));
|
||||
emit(const AuthError(message: 'Google sign-in cancelled'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(AuthError(message: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles [AuthAppleSignInRequested] events.
|
||||
///
|
||||
/// Attempts to sign in the user using Apple authentication.
|
||||
/// Emits [AuthAuthenticated] on success or [AuthError] on failure.
|
||||
Future<void> _onAppleSignInRequested(
|
||||
AuthAppleSignInRequested event,
|
||||
Emitter<AuthState> emit,
|
||||
@@ -121,13 +168,16 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
if (user != null) {
|
||||
emit(AuthAuthenticated(user: user));
|
||||
} else {
|
||||
emit(const AuthError(message: 'Connexion Apple annulée'));
|
||||
emit(const AuthError(message: 'Apple sign-in cancelled'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(AuthError(message: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles [AuthSignOutRequested] events.
|
||||
///
|
||||
/// Signs out the current user and emits [AuthUnauthenticated].
|
||||
Future<void> _onSignOutRequested(
|
||||
AuthSignOutRequested event,
|
||||
Emitter<AuthState> emit,
|
||||
@@ -136,6 +186,10 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
emit(AuthUnauthenticated());
|
||||
}
|
||||
|
||||
/// Handles [AuthPasswordResetRequested] events.
|
||||
///
|
||||
/// Sends a password reset email to the specified email address.
|
||||
/// Emits [AuthPasswordResetSent] on success or [AuthError] on failure.
|
||||
Future<void> _onPasswordResetRequested(
|
||||
AuthPasswordResetRequested event,
|
||||
Emitter<AuthState> emit,
|
||||
|
||||
Reference in New Issue
Block a user