feat: Implement group management features with Firestore integration and loading states
This commit is contained in:
26
lib/services/group_service.dart
Normal file
26
lib/services/group_service.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:travel_mate/models/group.dart';
|
||||
|
||||
class GroupService {
|
||||
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
|
||||
|
||||
Stream<List<Group>> getGroupsStream() {
|
||||
return _firestore.collection('groups').snapshots().map((snapshot) {
|
||||
return snapshot.docs.map((doc) {
|
||||
return Group.fromMap(doc.data(), doc.id);
|
||||
}).toList();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> createGroup(Group group) async {
|
||||
await _firestore.collection('groups').add(group.toMap());
|
||||
}
|
||||
|
||||
Future<void> updateGroup(Group group) async {
|
||||
await _firestore.collection('groups').doc(group.id).update(group.toMap());
|
||||
}
|
||||
|
||||
Future<void> deleteGroup(String groupId) async {
|
||||
await _firestore.collection('groups').doc(groupId).delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user