getCachedBillById method
- String billId
Retrieve a BillBaseDto specified with the billId from the database.
billId
of the cached bill.
Returns an instance of Success with the BillBaseDto object as data if it exists in the cache otherwise returns instance of Failure with type AnybillErrorType.genericError and code HttpStatus.notFound is returned.
In case of an internal error, instance of Failure with AnybillErrorType.unknown is returned
Implementation
Future<AnybillResult<BillBaseDto?>> getCachedBillById(String billId) async {
AnybillLogger.info("Tried to get cached bill by id");
try {
final data = await _billStore.getBillById(billId);
if (data != null) {
return AnybillResult.success(
HttpStatus.ok,
data: data,
);
} else {
return AnybillResult.failure(
type: AnybillErrorType.genericError,
code: HttpStatus.notFound,
);
}
}
// ----------------------------------------------------------------
catch (error, stacktrace) {
AnybillLogger.error(
error: error,
stacktrace: stacktrace,
library: runtimeType.toString(),
event: "getCachedBillById",
);
return AnybillResult.failure(
type: AnybillErrorType.unknown,
message: error.toString(),
);
}
}