fetchAllDocuments method
Fetches all documents from the Firestore collection.
This method logs the progress, performs the fetch operation, and handles errors. The logger also records the completion time.
Returns a Future list of all document data as a List of Maps.
Implementation
Future<List<Map<String, dynamic>>> fetchAllDocuments() async {
// Log the start of the fetch operation
final now = DateTime.now();
loggerService?.log("⌛ Fetching all documents in progress");
try {
// Fetch all documents from Firestore
final documents =
await firestoreReadService.fetchAllDocuments(collection);
return documents;
} catch (e) {
// Log any error encountered during the fetch
const errorMessage = 'Error fetching all documents';
loggerService?.logError(errorMessage, e.toString());
// Rethrow the error for further handling
rethrow;
} finally {
// Log the completion time of the fetch operation
loggerService?.logCompletionTime(now, 'Fetching all documents');
}
}