Skip to content
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

Merged
merged 4 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions packages/smooth_app/lib/background/background_task_details.dart
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';
Expand Down Expand Up @@ -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;
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Thanks for the answer, now it's clear

}
final Status status = await OpenFoodAPIClient.saveProduct(
getUser(),
_product,
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Not sure that answers your question, though.

language: getLanguage(),
country: getCountry(),
);
if (status.status != 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @M123-dev
Just out of curiosity, Can / Should we log this into sentry, Just wanted to make sure and keep a look into how many fails we do incur when saving data, would be helpful in understanding the background sync bug

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking that a alert would be more subtle for now
At least the user will know that something went wrong

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}');
}
}
}
7 changes: 5 additions & 2 deletions packages/smooth_app/lib/data_models/up_to_date_changes.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: deprecated_member_use

import 'package:openfoodfacts/model/Product.dart';
import 'package:smooth_app/data_models/operation_type.dart';
import 'package:smooth_app/database/dao_transient_operation.dart';
Expand Down Expand Up @@ -73,9 +71,14 @@ class UpToDateChanges {
if (change.ingredientsText != null) {
initial.ingredientsText = change.ingredientsText;
}
// ignore: deprecated_member_use
if (change.packaging != null) {
// ignore: deprecated_member_use
initial.packaging = change.packaging;
}
if (change.packagings != null) {
initial.packagings = change.packagings;
}
if (change.noNutritionData != null) {
initial.noNutritionData = change.noNutritionData;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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/database/dao_product.dart';
Expand Down Expand Up @@ -114,7 +115,7 @@ class ProductRefresher {
) async {
try {
// ignore: deprecated_member_use
final ProductResult result = await OpenFoodAPIClient.getProduct(
final ProductResultV3 result = await OpenFoodAPIClient.getProductV3(
getBarcodeQueryConfiguration(barcode),
);
if (result.product != null) {
Expand Down
Loading