getById method

  1. @override
Future<ReadResult<T>> getById(
  1. ReadOperation<T> operation
)
override

Loads the instance of T whose primary key is found at ReadOperation.itemId.

Implementation

@override
Future<ReadResult<T>> getById(ReadOperation<T> operation) async {
  if (getByIdHandler == null) {
    throw UnimplementedError();
  }

  try {
    final obj = await getByIdHandler!.call(operation);
    return ReadSuccess<T>(obj, details: operation.details);
  } on Exception catch (e) {
    _log.severe(e);
    return ReadFailure<T>(
      FailureReason.serverError,
      'Failed to load $T with Id ${operation.itemId}',
    );
  }
}