getGroupByCode method

Future<Group?> getGroupByCode(
  1. String code
)

Gets a group by its public link code

Implementation

Future<Group?> getGroupByCode(String code) async {
  try {
    final querySnapshot = await _firestore
        .collection(_collectionPath)
        .where('publicLinkCode', isEqualTo: code)
        .where('isPublic', isEqualTo: true)
        .limit(1)
        .get();

    if (querySnapshot.docs.isNotEmpty) {
      final doc = querySnapshot.docs.first;
      return Group.fromMap(doc.data(), doc.id);
    }
    return null;
  } catch (e) {
    print('Error getting group by code: $e');
    rethrow;
  }
}