Skip to content

Commit

Permalink
feat: 3430 - new packagings edit page based on api v3 (#3475)
Browse files Browse the repository at this point in the history
* feat: 3430 - new packagings edit page based on api v3

New file:
* `edit_new_packagings.dart`: Edit display of a product packagings (the new api V3 version).

Impacted files:
* `background_task_details.dart`: added specific save method call for api V3
* `edit_product_page.dart`: added call to new page `EditNewPackagings`
* `ocr_packaging_helper.dart`: minor unrelated refactoring
* `paged_user_product_query.dart`: specific field list
* `product_query.dart`: upgraded to api V3; added field `PACKAGINGS`; added specific field list for user-related searches (they do not support `PACKAGINGS`)
* `product_refresher.dart`: upgraded to api V3
* `simple_input_page.dart`: minor refactoring
* `simple_input_widget.dart`: refactoring about making the autocomplete widget reusable
* `up_to_date_changes.dart`: added new field `packagings`; minor unrelated refactoring

* Update packages/smooth_app/lib/pages/product/edit_product_page.dart

Co-authored-by: Pierre Slamich <[email protected]>

* feat: 3430 - dart format

Co-authored-by: Pierre Slamich <[email protected]>
Co-authored-by: Pierre Slamich <[email protected]>
  • Loading branch information
3 people authored Dec 27, 2022
1 parent e2a8464 commit 09a982a
Show file tree
Hide file tree
Showing 10 changed files with 491 additions and 122 deletions.
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;
}
final Status status = await OpenFoodAPIClient.saveProduct(
getUser(),
_product,
language: getLanguage(),
country: getCountry(),
);
if (status.status != 1) {
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

0 comments on commit 09a982a

Please sign in to comment.