getTotalExercises method

Future<int> getTotalExercises(
  1. String userEmail
)

Returns the total number of exercises the user has logged.

Implementation

Future<int> getTotalExercises(String userEmail) async {
  final userSnapshot = await firestore
      .collection('users')
      .where('email', isEqualTo: userEmail)
      .get();

  if (userSnapshot.docs.isEmpty) return 0;

  final userDocId = userSnapshot.docs.first.id;

  final exerciseLogsSnapshot = await firestore
      .collection('users')
      .doc(userDocId)
      .collection('exerciseLogs')
      .get();

  return exerciseLogsSnapshot.docs.length;
}