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: 617 - new "save packagings V3" feature #640

Merged
merged 2 commits into from
Dec 16, 2022

Conversation

monsieurtanuki
Copy link
Contributor

New files:

  • api_saveProductV3_test.dart: Integration tests around the "save packagings V3" feature.
  • ProductPackaging.dart: Packaging component for a product, e.g. recyclable bottle made of glass.
  • ProductPackaging.g.dart: generated

Impacted files:

  • AbstractQueryConfiguration.dart: populated parameter tags_lc
  • api_getProduct_test.dart: removed references to now deprecated field packaging; added a test about the new packagings field
  • api_saveProduct_test.dart: skipped one 504 test; removed references to deprecated field packaging
  • HttpHelper.dart: new method doPatchRequest; minor refactoring
  • openfoodfacts.dart: new method temporarySaveProductV3
  • Product.dart: deprecated field packaging; added field packagings
  • Product.g.dart: generated
  • ProductFields.dart: deprecated PACKAGING; added PACKAGINGS and RAW
  • ProductSearchQueryConfiguration.dart: added api version parameter
  • UriHelper.dart: new method getPatchUri

What

  • Here we implement the new "save packagings V3" feature.
  • The new packagings product field provides detailed information about the packaging, cf. new class ProductPackaging
  • Unfortunately for the moment only packagings is supported with save/V3. That means that packagings should be saved with a different call from the other fields.

Fixes bug(s)

New files:
* `api_saveProductV3_test.dart`: Integration tests around the "save packagings V3" feature.
* `ProductPackaging.dart`: Packaging component for a product, e.g. recyclable bottle made of glass.
* `ProductPackaging.g.dart`: generated

Impacted files:
* `AbstractQueryConfiguration.dart`: populated parameter `tags_lc`
* `api_getProduct_test.dart`: removed references to now deprecated field `packaging`; added a test about the new packagings field
* `api_saveProduct_test.dart`: skipped one 504 test; removed references to deprecated field `packaging`
* `HttpHelper.dart`: new method `doPatchRequest`; minor refactoring
* `openfoodfacts.dart`: new method `temporarySaveProductV3`
* `Product.dart`: deprecated field `packaging`; added field `packagings`
* `Product.g.dart`: generated
* `ProductFields.dart`: deprecated `PACKAGING`; added `PACKAGINGS` and `RAW`
* `ProductSearchQueryConfiguration.dart`: added api version parameter
* `UriHelper.dart`: new method `getPatchUri`
Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @monsieurtanuki just some minor comments

Comment on lines +315 to +316
// TODO: deprecated from 2022-12-16; remove when old enough
@Deprecated('User packagingS instead')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO: deprecated from 2022-12-16; remove when old enough
@Deprecated('User packagingS instead')
// TODO: deprecated from 2022-12-16; remove when old enough
@Deprecated('Use [packagings] instead')

@@ -468,7 +475,8 @@ class Product extends JsonObject {
this.labels,
this.labelsTags,
this.labelsTagsInLanguages,
this.packaging,
// TODO: deprecated from 2022-12-16; remove when old enough
@Deprecated('Use packagingS field instead') this.packaging,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@Deprecated('Use packagingS field instead') this.packaging,
@Deprecated('Use [packagings] field instead') this.packaging,

Feel free to leave it with the capital S

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The square bracket syntax is unfortunately not detected in strings, only in /// comments.

///
/// For the moment that's the only field supported in WRITE by API V3.
/// Long term target is of course more something like [saveProduct].
static Future<ProductResultV3> temporarySaveProductV3(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
static Future<ProductResultV3> temporarySaveProductV3(
static Future<ProductResultV3> temporarySaveProductPackagingsV3(

Just a suggestion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could make sense but in the long run I expect more fields to match V3 (e.g. one by month) : I'm not going to create a different method for each.

Comment on lines +32 to +35
static Map<String, dynamic>? addUserAgentParameters(
Map<String, dynamic>? map,
) {
map ??= <String, String>{};
map ??= <String, dynamic>{};
Copy link
Member

Choose a reason for hiding this comment

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

Why dynamic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the new method doPatchRequest the input can be Map<String, dynamic>, and not Map<String, String>.
More specifically in that case:

    parameterMap['product']['packagings'] = packagings;

@monsieurtanuki monsieurtanuki merged commit 55ffbf2 into openfoodfacts:master Dec 16, 2022
@monsieurtanuki
Copy link
Contributor Author

Thank you @M123-dev for your fast review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for API v3 Product WRITE requests to add / edit packaging components
3 participants