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

Fix: Added missing product fields to ProductField enum #331

Merged
merged 4 commits into from Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/model/Product.dart
@@ -1,10 +1,11 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:openfoodfacts/model/AttributeGroup.dart';
import 'package:openfoodfacts/model/Attribute.dart';
import 'package:openfoodfacts/model/AttributeGroup.dart';
import 'package:openfoodfacts/model/ProductImage.dart';
import 'package:openfoodfacts/utils/JsonHelper.dart';
import 'package:openfoodfacts/utils/LanguageHelper.dart';
import 'package:openfoodfacts/utils/ProductFields.dart';

import '../interface/JsonObject.dart';
import 'Additives.dart';
import 'Allergens.dart';
Expand Down Expand Up @@ -102,6 +103,9 @@ class Product extends JsonObject {
includeIfNull: false)
Map<OpenFoodFactsLanguage, String>? productNameInLanguages;

@JsonKey(name: 'generic_name')
String? genericName;

Copy link
Contributor

Choose a reason for hiding this comment

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

What's that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I checked the diffs and this was in the ProductFields but not in the Product, Its in the normal reponses and since its particially already in the code I just added it

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough!

Nothing personal, but there are already tons of fields in Product (50+) and none of them has comments.
Adding a String? called genericName, why not, next one is going to be dynamic justSomething?

More seriously: we should definitely add comments on the Product fields. In another PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes there I agree with you, we should make in any case. In fact, I've been thinking about updating the entire documentation a bit for a while now.

I don't know how to approach this, but it would also be good to somehow manage to have the products in just one place and not in two files in two places each.

@JsonKey(name: 'brands', includeIfNull: false)
String? brands;
@JsonKey(name: 'brands_tags', includeIfNull: false)
Expand Down Expand Up @@ -322,6 +326,7 @@ class Product extends JsonObject {
{this.barcode,
this.productName,
this.productNameInLanguages,
this.genericName,
this.brands,
this.brandsTags,
this.countries,
Expand Down
2 changes: 2 additions & 0 deletions lib/model/Product.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/utils/ProductFields.dart
Expand Up @@ -15,6 +15,7 @@ enum ProductField {
LANGUAGE,
QUANTITY,
SERVING_SIZE,
SERVING_QUANTITY,
PACKAGING_QUANTITY,
FRONT_IMAGE,
SELECTED_IMAGE,
Expand Down Expand Up @@ -43,15 +44,20 @@ enum ProductField {
CATEGORIES,
CATEGORIES_TAGS,
CATEGORIES_TAGS_IN_LANGUAGES,
LABELS,
LABELS_TAGS,
LABELS_TAGS_IN_LANGUAGES,
PACKAGING,
PACKAGING_TAGS,
MISC_TAGS,
STATES_TAGS,
TRACES_TAGS,
STORES_TAGS,
INGREDIENTS_ANALYSIS_TAGS,
ALLERGENS,
ENVIRONMENT_IMPACT_LEVELS,
ATTRIBUTE_GROUPS,
LAST_MODIFIED,
ECOSCORE_GRADE,
ECOSCORE_SCORE,
ECOSCORE_DATA,
Expand All @@ -73,6 +79,7 @@ extension ProductFieldExtension on ProductField {
ProductField.LANGUAGE: 'lang',
ProductField.QUANTITY: 'quantity',
ProductField.SERVING_SIZE: 'serving_size',
ProductField.SERVING_QUANTITY: 'serving_quantity',
ProductField.PACKAGING_QUANTITY: 'product_quantity',
ProductField.FRONT_IMAGE: 'image_small_url',
ProductField.IMAGE_FRONT_URL: 'image_front_url',
Expand Down Expand Up @@ -101,15 +108,20 @@ extension ProductFieldExtension on ProductField {
ProductField.CATEGORIES: 'categories',
ProductField.CATEGORIES_TAGS: 'categories_tags',
ProductField.CATEGORIES_TAGS_IN_LANGUAGES: 'categories_tags_',
ProductField.LABELS: 'labels',
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably would be worth checking in a test that when we ask for those fields in a get product query, we actually get them.

Copy link
Member Author

Choose a reason for hiding this comment

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

On it

ProductField.LABELS_TAGS: 'labels_tags',
ProductField.LABELS_TAGS_IN_LANGUAGES: 'labels_tags_',
ProductField.PACKAGING: 'packaging',
ProductField.PACKAGING_TAGS: 'packaging_tags',
ProductField.MISC_TAGS: 'misc',
ProductField.STATES_TAGS: 'states_tags',
ProductField.TRACES_TAGS: 'traces_tags',
ProductField.STORES_TAGS: 'stores_tags',
ProductField.INGREDIENTS_ANALYSIS_TAGS: 'ingredients_analysis_tags',
ProductField.ALLERGENS: 'allergens_tags',
ProductField.ENVIRONMENT_IMPACT_LEVELS: 'environment_impact_level_tags',
ProductField.ATTRIBUTE_GROUPS: 'attribute_groups',
ProductField.LAST_MODIFIED: 'last_modified_t',
ProductField.ECOSCORE_GRADE: 'ecoscore_grade',
ProductField.ECOSCORE_SCORE: 'ecoscore_score',
ProductField.ECOSCORE_DATA: 'ecoscore_data',
Expand Down