getBooks method
Loads books data for the specified collection.
Implementation
Future<List<Book>> getBooks(Collection collection) async {
if (_booksCache.containsKey(collection)) {
return _booksCache[collection]!;
}
String collectionName = _getCollectionName(collection);
String path = 'data/$collectionName/books.json';
File file = File(path);
if (!await file.exists()) {
throw Exception('Books file not found for $collectionName at $path');
}
String contents = await file.readAsString();
List<dynamic> jsonData = jsonDecode(contents);
List<Book> books = jsonData.map((json) => Book.fromJson(json)).toList();
_booksCache[collection] = books;
return books;
}