index method

  1. @override
Future<List<Map<String, dynamic>>> index (
  1. [Map<String, dynamic> params]
)
override

GET / Fetch all resources. Usually returns a List.

Implementation

@override
Future<List<Map<String, dynamic>>> index(
    [Map<String, dynamic> params]) async {
  List<Document> documents;
  if (params == null ||
      (params.containsKey('query') && (params['query'] as Map).isEmpty) ||
      (!params.containsKey(r'$where') && !params.containsKey('query'))) {
    documents = await collection.get();
  } else {
    FirestoreWhereFilter whereFilter;
    if (params.containsKey('query')) {
      Map<String, dynamic> queryMap = params['query'];
      whereFilter = FirestoreWhereFilter(
          queryMap.keys.first, queryMap.values.first,
          comparisonType: ComparisonType.isEqualTo);
    }
    if (params.containsKey(r'$where')) {
      whereFilter = params[r'$where'];
    }

    documents = await _whereFilter(collection, whereFilter).get();
  }
  return documents.map((doc) => _mapWithId(doc)).toList();
}