updateIsFavourite method
Updates the favourite status of a given bill
-
requestCount
can be used to determine the number of repeated requests before a failure is returned if the call is not successful. -
billId
of the bill that is supposed to be favourited or unfavourited. -
isFavourite
stating the desired favourite status of the bill
Returns a AnybillResult.success that contains the status code.
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<void>> updateIsFavourite({
int requestCount = 2,
required String billId,
required bool isFavourite,
}) async {
AnybillLogger.info(
"Tried update bill $billId isFavourite with $isFavourite",
);
try {
final token = await _tokenProvider.getToken();
if (token == null) {
return AnybillResult.failure(
type: AnybillErrorType.noUserError,
);
}
// Makes a request to update isFavourite
await _billService.updateBillSetisfavouriteWithBillId(
token: token,
billId: billId,
isFavourite: isFavourite,
);
return AnybillResult.success(
HttpStatus.noContent,
);
}
// ----------------------------------------------------------------
catch (error, stacktrace) {
return ErrorHandler.handleError(
error,
stacktrace,
requestCount: requestCount,
request: () => updateIsFavourite(
requestCount: requestCount - 1,
billId: billId,
isFavourite: isFavourite,
),
event: "updateIsFavourite",
library: runtimeType.toString(),
);
}
}