feat: Implement account management functionality with loading, creation, and error handling
This commit is contained in:
@@ -103,15 +103,44 @@ class AccountRepository {
|
||||
return await _firestore.collection('accounts').doc(accountId).get();
|
||||
}
|
||||
|
||||
Future<void> createAccount(Map<String, dynamic> accountData) async {
|
||||
await _firestore.collection('accounts').add(accountData);
|
||||
Future<void> updateAccount(String accountId, Account account) async {
|
||||
try {
|
||||
await _firestore.collection('accounts').doc(accountId).update(account.toMap());
|
||||
} catch (e) {
|
||||
_errorService.logError('account_repository.dart', 'Erreur lors de la mise à jour du compte: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateAccount(String accountId, Map<String, dynamic> accountData) async {
|
||||
await _firestore.collection('accounts').doc(accountId).update(accountData);
|
||||
Future<void> deleteAccount(String tripId) async {
|
||||
try {
|
||||
final querySnapshot = await _firestore
|
||||
.collection('accounts')
|
||||
.where('tripId', isEqualTo: tripId)
|
||||
.get();
|
||||
if (querySnapshot.docs.isEmpty) {
|
||||
throw Exception('Aucun compte trouvé pour ce voyage');
|
||||
}
|
||||
|
||||
final docId = querySnapshot.docs.first.id;
|
||||
|
||||
final membersSnapshot = await _membersCollection(docId).get();
|
||||
for (var memberDoc in membersSnapshot.docs) {
|
||||
await _membersCollection(docId).doc(memberDoc.id).delete();
|
||||
}
|
||||
await _accountCollection.doc(docId).delete();
|
||||
} catch (e) {
|
||||
_errorService.logError('account_repository.dart', 'Erreur lors de la suppression du compte: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteAccount(String accountId) async {
|
||||
await _firestore.collection('accounts').doc(accountId).delete();
|
||||
Stream<List<GroupMember>> watchGroupMembers(String accountId) {
|
||||
return _membersCollection(accountId).snapshots().map(
|
||||
(snapshot) => snapshot.docs
|
||||
.map((doc) => GroupMember.fromMap(
|
||||
doc.data() as Map<String, dynamic>,
|
||||
doc.id,
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user