feat: Implement group management with BLoC pattern; add GroupBloc, GroupRepository, and related models
NOT FUNCTIONNAL
This commit is contained in:
@@ -8,6 +8,7 @@ import '../../blocs/trip/trip_event.dart';
|
||||
import '../../blocs/group/group_bloc.dart';
|
||||
import '../../blocs/group/group_event.dart';
|
||||
import '../../data/models/group.dart';
|
||||
import '../../data/models/group_member.dart';
|
||||
import '../../services/user_service.dart';
|
||||
|
||||
class CreateTripContent extends StatefulWidget {
|
||||
@@ -426,10 +427,9 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
});
|
||||
|
||||
try {
|
||||
// Convertir les emails en IDs
|
||||
List<String> participantIds = await _changeUserEmailById(_participants);
|
||||
final participantsData = await _getParticipantsData(_participants);
|
||||
List<String> participantIds = participantsData.map((p) => p['id'] as String).toList();
|
||||
|
||||
// Ajouter le créateur
|
||||
if (!participantIds.contains(currentUser.id)) {
|
||||
participantIds.insert(0, currentUser.id);
|
||||
}
|
||||
@@ -449,20 +449,38 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
|
||||
// Créer le groupe
|
||||
context.read<TripBloc>().add(TripCreateRequested(trip: trip));
|
||||
|
||||
// Attendre que le trip soit créé (simplifié)
|
||||
await Future.delayed(Duration(milliseconds: 500));
|
||||
|
||||
final group = Group(
|
||||
id: '',
|
||||
id: '',
|
||||
name: _titleController.text.trim(),
|
||||
members: participantIds,
|
||||
tripId: '',
|
||||
createdBy: currentUser.id,
|
||||
);
|
||||
|
||||
// Utiliser les BLoCs pour créer
|
||||
context.read<TripBloc>().add(TripCreateRequested(trip: trip));
|
||||
context.read<GroupBloc>().add(GroupCreateRequested(group: group));
|
||||
final groupMembers = <GroupMember>[
|
||||
GroupMember(
|
||||
userId: currentUser.id,
|
||||
firstName: currentUser.prenom,
|
||||
pseudo: currentUser.prenom, // Par défaut = prénom
|
||||
role: 'admin',
|
||||
),
|
||||
...participantsData.map((p) => GroupMember(
|
||||
userId: p['id'] as String,
|
||||
firstName: p['firstName'] as String,
|
||||
pseudo: p['firstName'] as String, // Par défaut = prénom
|
||||
role: 'member',
|
||||
)),
|
||||
];
|
||||
|
||||
if (mounted) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
|
||||
context.read<GroupBloc>().add(CreateGroupWithMembers(
|
||||
group: group,
|
||||
members: groupMembers,
|
||||
));
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -481,14 +499,24 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<String>> _changeUserEmailById(List<String> participants) async {
|
||||
List<String> ids = [];
|
||||
// ...existing code...
|
||||
|
||||
for (String email in participants) {
|
||||
// Récupérer les IDs et prénoms des participants
|
||||
Future<List<Map<String, String>>> _getParticipantsData(List<String> emails) async {
|
||||
List<Map<String, String>> participantsData = [];
|
||||
|
||||
for (String email in emails) {
|
||||
try {
|
||||
final id = await _userService.getUserIdByEmail(email);
|
||||
if (id != null) {
|
||||
ids.add(id);
|
||||
final userId = await _userService.getUserIdByEmail(email);
|
||||
if (userId != null) {
|
||||
// Récupérer le prénom de l'utilisateur
|
||||
final userDoc = await _userService.getUserById(userId);
|
||||
final firstName = userDoc?.prenom ?? 'Utilisateur';
|
||||
|
||||
participantsData.add({
|
||||
'id': userId,
|
||||
'firstName': firstName,
|
||||
});
|
||||
} else {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -500,10 +528,10 @@ class _CreateTripContentState extends State<CreateTripContent> {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('Erreur: $e');
|
||||
print('Erreur lors de la récupération de l\'utilisateur: $e');
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
return participantsData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user