updateBills method
- {int requestCount = 2}
Retrieve a List<BillBaseDto> with the bills of the current authenticated user using the database. If there are no bills saved in the local database, all bills are fetched. If there are bills the last modified date of the latest bill is used to update the bills.
Returns a AnybillResult.success that contains the status code and the bill list.
Throws a AnybillResult.failure with the specified information gained from the API. This could be a DioException when a generic errors occurred or a different Exception for critical errors that couldn't be caught.
Implementation
Future<AnybillResult<List<BillBaseDto>>> updateBills({
int requestCount = 2,
}) async {
AnybillLogger.info("Tried to update bills");
try {
final cachedBills = await _billStore.getAllBills();
if (cachedBills.isEmpty) {
await getBills(take: 1000);
} else {
DateTime? latestChangedDate =
await _billStore.getLatestChangedBillDate();
await getBills(changesSince: latestChangedDate?.toIso8601String());
}
return AnybillResult.success(
HttpStatus.ok,
data: await _billStore.getAllBills(),
);
}
// ----------------------------------------------------------------
catch (error, stacktrace) {
return ErrorHandler.handleError(
error,
stacktrace,
requestCount: requestCount,
request: () => updateBills(
requestCount: requestCount - 1,
),
event: "updateBills",
library: runtimeType.toString(),
);
}
}