deleteGroup method

Future<void> deleteGroup(
  1. String groupId
)

Deletes a group

Implementation

Future<void> deleteGroup(String groupId) async {
  try {
    // Delete the locations subcollection first
    final locationsSnapshot = await _firestore
        .collection(_collectionPath)
        .doc(groupId)
        .collection(_locationSubcollection)
        .get();

    // Use a batch to delete all locations
    final batch = _firestore.batch();
    for (final doc in locationsSnapshot.docs) {
      batch.delete(doc.reference);
    }

    // Then delete the group document
    batch.delete(_firestore.collection(_collectionPath).doc(groupId));

    await batch.commit();
  } catch (e) {
    print('Error deleting group: $e');
    rethrow;
  }
}