execute method
- LocalDatabase localDatabase
override
Executes the background task: upload, download, update locally.
Implementation
@override
Future<void> execute(LocalDatabase localDatabase) async {
final BackgroundCropResult cropResult =
await BackgroundTaskImage.cropIfNeeded(
fullPath: fullPath,
rotationDegrees: rotationDegrees,
cropX1: cropX1,
cropY1: cropY1,
cropX2: cropX2,
cropY2: cropY2,
forceCompression: true,
eraserCoordinates: eraserCoordinates,
);
final String? path = cropResult.filePath;
if (path == null) {
// TODO(monsieurtanuki): maybe something more refined when we dismiss the picture, like alerting the user, though it's not supposed to happen anymore from upstream.
return;
}
final String bearerToken = await getBearerToken(localDatabase);
// proof upload
final Uri initialImageUri = Uri.parse(path);
final MediaType initialMediaType = HttpHelper().imagineMediaType(
initialImageUri.path,
)!;
final MaybeError<Proof> uploadProof = await OpenPricesAPIClient.uploadProof(
createProofParameters: CreateProofParameters(proofType)
..date = date
..currency = currency
..locationOSMId = locationOSMId
..locationOSMType = locationOSMType
..readyForPriceTagValidation = readyForPriceTagValidation,
imageUri: initialImageUri,
mediaType: initialMediaType,
bearerToken: bearerToken,
uriHelper: ProductQuery.uriPricesHelper,
);
if (uploadProof.isError) {
throw Exception('Could not upload proof: ${uploadProof.error}');
}
await BackgroundTaskAddOtherPrice.addTask(
context: null,
localDatabase: localDatabase,
proofId: uploadProof.value.id,
date: date,
currency: currency,
locationOSMId: locationOSMId,
locationOSMType: locationOSMType,
barcodes: barcodes,
categories: categories,
origins: origins,
labels: labels,
pricePers: pricePers,
pricesAreDiscounted: pricesAreDiscounted,
prices: prices,
pricesWithoutDiscount: pricesWithoutDiscount,
discountTypes: discountTypes,
);
}