-
-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 3430 - new packagings edit page based on api v3 #3475
Changes from all commits
cf1fb48
f78dab3
119a1ed
6010cfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import 'dart:convert'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:openfoodfacts/model/ProductResultV3.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:smooth_app/background/abstract_background_task.dart'; | ||
|
@@ -113,12 +114,31 @@ class BackgroundTaskDetails extends AbstractBackgroundTask { | |
/// Uploads the product changes. | ||
@override | ||
Future<void> upload() async { | ||
// TODO(AshAman999): check returned Status | ||
await OpenFoodAPIClient.saveProduct( | ||
if (_product.packagings != null) { | ||
// For the moment, we can only save "packagings" with V3, | ||
// and V3 can only save "packagings". | ||
final ProductResultV3 result = | ||
await OpenFoodAPIClient.temporarySaveProductV3( | ||
getUser(), | ||
_product.barcode!, | ||
packagings: _product.packagings, | ||
language: getLanguage(), | ||
country: getCountry(), | ||
); | ||
if (result.status != ProductResultV3.statusSuccess && | ||
result.status != ProductResultV3.statusWarning) { | ||
throw Exception('Could not save product - ${result.errors}'); | ||
} | ||
return; | ||
} | ||
final Status status = await OpenFoodAPIClient.saveProduct( | ||
getUser(), | ||
_product, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we remove the packaging from here, or are they ignored by the older api versions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I said in a previous comment, save v3 can only save packagings, and the other save method can save the rest. So we need both. |
||
language: getLanguage(), | ||
country: getCountry(), | ||
); | ||
if (status.status != 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello @M123-dev There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the Exception will be automatically collected by sentry, but this is to be checked There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AshAman999 More broadly, the question is again: what should we do with failing changes? Run them forever? Ignore them? Alert the user? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking that a alert would be more subtle for now About retires I am not sure that we are going to have so many of those occurrences for failures, I guess next setry report will reveal these data |
||
throw Exception('Could not save product - ${status.error}'); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit confused about the return statement here, do you think it's needed here ?
Suppose I am offline now and I did some edits to the product name and then to this packagings
So when I connect back to the internet, the first block ie the code from if condition would run, and then after successful, it would simply return and won't do the save query for the rest of the changes,
Is there something I am missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't merge changes, and just save them sequentially one by one.
In the case we want to save packagings, we are going to save only this field. Therefore only in api v3, and when it's done there's nothing else to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the answer, now it's clear