getListByFilterEx method
Gets a list of data items retrieved by a given filter and sorted according to sort parameters.
This method shall be called by a public getListByFilter method from child class that receives FilterParams and converts them into a filter function.
correlationId
(optional) transaction id to trace execution through call chain.filter
(optional) a filter JSON objectsort
(optional) sorting JSON object Return Future that receives a data list. Throw error
Implementation
Future<List<T>> getListByFilterEx(String? correlationId,
Map<String, dynamic>? filter, Map<String, dynamic>? sort) async {
// Configure options
var query = mngquery.SelectorBuilder();
var selector = <String, dynamic>{};
if (filter != null && filter.isNotEmpty) {
selector[r'$query'] = filter;
}
if (sort != null) {
selector['orderby'] = sort;
}
query.raw(selector);
var items = <T>[];
var results = await collection?.find(query).toList() ?? [];
for (var item in results) {
items.add(convertToPublic(item));
}
logger.trace(
correlationId, 'Retrieved %d from %s', [items.length, collectionName]);
return items;
}