Refactor signup page to use BLoC pattern and implement authentication repository

- Updated signup.dart to replace Provider with BLoC for state management.
- Created AuthRepository to handle authentication logic and Firestore user management.
- Added TripRepository and UserRepository for trip and user data management.
- Implemented methods for user sign-in, sign-up, and data retrieval in repositories.
- Enhanced trip management with create, update, delete, and participant management functionalities.
- Updated AuthService to include new methods for sign-in and sign-up.
- Removed unnecessary print statements from TripService for cleaner code.
- Added dependencies for flutter_bloc and equatable in pubspec.yaml.

Not tested yet
This commit is contained in:
Dayron
2025-10-14 10:53:28 +02:00
parent a467b92979
commit c4588a65c0
31 changed files with 1500 additions and 689 deletions

View File

@@ -9,7 +9,7 @@ class AuthService {
Stream<User?> get authStateChanges => firebaseAuth.authStateChanges();
Future<UserCredential> signIn({
Future<UserCredential> signInWithEmailAndPassword({
required String email,
required String password
}) async {
@@ -17,7 +17,7 @@ class AuthService {
email: email, password: password);
}
Future<UserCredential> createAccount({
Future<UserCredential> signUpWithEmailAndPassword({
required String email,
required String password
}) async {
@@ -100,5 +100,9 @@ class AuthService {
rethrow;
}
}
Future signInWithApple() async {
// TODO: Implémenter la connexion avec Apple
}
}

View File

@@ -1,5 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import '../models/trip.dart';
import '../data/models/trip.dart';
class TripService {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
@@ -53,26 +53,19 @@ class TripService {
.collection(_tripsCollection)
.snapshots()
.map((snapshot) {
print('=== NOUVEAU SNAPSHOT ===');
print('Nombre de documents: ${snapshot.docs.length}');
final List<Trip> trips = [];
for (int i = 0; i < snapshot.docs.length; i++) {
var doc = snapshot.docs[i];
print('\n--- Document $i (${doc.id}) ---');
try {
final data = doc.data() as Map<String, dynamic>;
final data = doc.data();
// Vérifier si l'utilisateur est impliqué dans ce voyage
final String createdBy = data['createdBy']?.toString() ?? '';
final List<dynamic> participants = data['participants'] ?? [];
print('CreatedBy: "$createdBy"');
print('UserId: "$userId"');
print('Participants: $participants');
bool userIsInvolved = false;
String reason = '';
@@ -88,20 +81,11 @@ class TripService {
reason = reason.isEmpty ? 'Participant par ID' : '$reason + Participant par ID';
}
print('Utilisateur impliqué: $userIsInvolved');
print('Raison: $reason');
if (userIsInvolved) {
print('Tentative de conversion du trip...');
final trip = _convertDocumentToTrip(doc.id, data);
if (trip != null) {
trips.add(trip);
print('Trip ajouté: ${trip.title}');
} else {
print('Échec de la conversion du trip');
}
} else {
print('Utilisateur non impliqué dans ce voyage');
}
} catch (e, stackTrace) {
print('Erreur lors du traitement du document ${doc.id}: $e');
@@ -109,14 +93,6 @@ class TripService {
}
}
print('\n=== RÉSUMÉ ===');
print('Trips trouvés: ${trips.length}');
if (trips.isNotEmpty) {
for (int i = 0; i < trips.length; i++) {
print(' ${i+1}. ${trips[i].title} (${trips[i].id})');
}
}
// Trier par date de création (les plus récents en premier)
trips.sort((a, b) {
try {
@@ -138,8 +114,6 @@ class TripService {
// Obtenir les voyages d'un utilisateur (version simplifiée)
Future<List<Trip>> getTripsByUser(String userId) async {
try {
print('Récupération des voyages pour userId: $userId');
// Récupérer d'abord les voyages créés par l'utilisateur
final QuerySnapshot createdTrips = await _firestore
.collection(_tripsCollection)
@@ -176,9 +150,7 @@ class TripService {
}
// Méthode helper pour convertir un document Firestore en Trip
Trip? _convertDocumentToTrip(String docId, Map<String, dynamic> data) {
print('\n=== CONVERSION TRIP $docId ===');
Trip? _convertDocumentToTrip(String docId, Map<String, dynamic> data) {
try {
// Créer une copie des données pour ne pas modifier l'original
Map<String, dynamic> processedData = Map<String, dynamic>.from(data);
@@ -211,7 +183,7 @@ class TripService {
return trip;
} catch (e, stackTrace) {
print('Erreur lors de la conversion du document $docId: $e');
print('Erreur lors de la conversion du document $docId: $e');
print('StackTrace: $stackTrace');
return null;
}