doDataSourceOperation<T> function

Future<List<T?>?> doDataSourceOperation<T>(
  1. DataSource<T> dataSource,
  2. DataSourceOperation operation,
  3. Map<String, String>? parameters, [
  4. List<T>? dataList,
])

Performs a DataSourceOperation over dataSource instance.

Implementation

Future<List<T?>?> doDataSourceOperation<T>(DataSource<T> dataSource,
    DataSourceOperation operation, Map<String, String>? parameters,
    [List<T>? dataList]) {
  switch (operation) {
    case DataSourceOperation.get:
      return dataSource.get(parameters);
    case DataSourceOperation.find:
      return dataSource.find(parameters);
    case DataSourceOperation.findByID:
      {
        var id = findKeyValue(parameters, ['id', 'key'], true);
        return dataSource.findByID(id);
      }
    case DataSourceOperation.findByIDRange:
      {
        var fromID = findKeyValue(
            parameters,
            ['fromid', 'from_id', 'from-id', 'fromkey', 'from_key', 'from-key'],
            true);
        var toID = findKeyValue(parameters,
            ['toid', 'to_id', 'to-id', 'tokey', 'to_key', 'to-key'], true);
        return dataSource.findByIDRange(fromID, toID);
      }
    case DataSourceOperation.put:
      {
        var dataReceiver = dataSource as DataReceiver;
        return dataReceiver.put(parameters: parameters, dataList: dataList)
            as Future<List<T?>?>;
      }
    default:
      return Future.value(null);
  }
}