From 1d36e82e8b578a7cd63584f3f4a7e4c4d82cf2b3 Mon Sep 17 00:00:00 2001 From: Affan Date: Wed, 22 Jan 2025 13:09:44 +0530 Subject: [PATCH 01/10] Add new localized fields for conservation_conditions and customer_service in Product object - Added 'conservation_conditions_languages' and 'customer_service_languages' fields to the Product object for better multilingual support. - Fixed issue with handling French-specific fields by using language-based keys. --- lib/src/model/product.dart | 34 +++++++++++++++++++++++++++++++ lib/src/utils/product_fields.dart | 32 +++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/lib/src/model/product.dart b/lib/src/model/product.dart index 2b150fe921..9f720d8871 100644 --- a/lib/src/model/product.dart +++ b/lib/src/model/product.dart @@ -109,6 +109,38 @@ class Product extends JsonObject { toJson: LanguageHelper.toJsonStringMap) Map? productNameInLanguages; + /// The conservation conditions of the product, either set directly or taken from one of the localizations. + /// + /// Prefer using [conservationConditionsInLanguages] for more accurate and localized data. + @JsonKey(name: 'conservation_conditions') + String? conservation_conditions; + + /// Localized conservation conditions of the product, stored in a map where each language is represented by its respective key. + /// + /// This field is useful when you need to retrieve conservation conditions in a specific language. + /// For general usage, rely on [conservation_conditions] or the localization-specific fields. + @JsonKey( + name: 'conservation_conditions_in_languages', + fromJson: LanguageHelper.fromJsonStringMap, + toJson: LanguageHelper.toJsonStringMap) + Map? conservationConditionsInLanguages; + + /// The customer service information for the product, either set directly or taken from one of the localizations. + /// + /// Prefer using [customerServiceInLanguages] for more accurate and localized data. + @JsonKey(name: 'customer_service') + String? customer_service; + + /// Localized customer service information for the product, stored in a map where each language is represented by its respective key. + /// + /// This field is useful when you need to retrieve customer service information in a specific language. + /// For general usage, rely on [customer_service] or the localization-specific fields. + @JsonKey( + name: 'customer_service_in_languages', + fromJson: LanguageHelper.fromJsonStringMap, + toJson: LanguageHelper.toJsonStringMap) + Map? customerServiceInLanguages; + /// Common name. Example: "Chocolate bar with milk and hazelnuts". @JsonKey(name: 'generic_name') String? genericName; @@ -604,6 +636,8 @@ class Product extends JsonObject { {this.barcode, this.productName, this.productNameInLanguages, + this.conservation_conditions, + this.customer_service, this.genericName, this.brands, this.brandsTags, diff --git a/lib/src/utils/product_fields.dart b/lib/src/utils/product_fields.dart index b17af30be7..8bf6fd7154 100644 --- a/lib/src/utils/product_fields.dart +++ b/lib/src/utils/product_fields.dart @@ -17,6 +17,36 @@ enum ProductField implements OffTagged { offTag: 'product_name_languages', inLanguagesProductField: ProductField.NAME_IN_LANGUAGES, isAllLanguages: true, + ), + CONSERVATION_CONDITIONS( + offTag: 'conservation_conditions', + inLanguagesProductField: ProductField.CONSERVATION_CONDITIONS_IN_LANGUAGES, + ), + + CONSERVATION_CONDITIONS_IN_LANGUAGES( + offTag: 'conservation_conditions_', + isInLanguages: true, + ), + + CONSERVATION_CONDITIONS_ALL_LANGUAGES( + offTag: 'conservation_conditions_languages', + inLanguagesProductField: ProductField.CONSERVATION_CONDITIONS_IN_LANGUAGES, + isAllLanguages: true, + ), + CUSTOMER_SERVICE( + offTag: 'customer_service', + inLanguagesProductField: ProductField.CUSTOMER_SERVICE_IN_LANGUAGES, + ), + + CUSTOMER_SERVICE_IN_LANGUAGES( + offTag: 'customer_service_', + isInLanguages: true, + ), + + CUSTOMER_SERVICE_ALL_LANGUAGES( + offTag: 'customer_service_languages', + inLanguagesProductField: ProductField.CUSTOMER_SERVICE_IN_LANGUAGES, + isAllLanguages: true, ), GENERIC_NAME( offTag: 'generic_name', @@ -287,6 +317,8 @@ enum ProductField implements OffTagged { @Deprecated('Use ProductField.getInLanguagesList() instead') const Set fieldsInLanguages = { ProductField.NAME_IN_LANGUAGES, + ProductField.CONSERVATION_CONDITIONS_IN_LANGUAGES, + ProductField.CUSTOMER_SERVICE_IN_LANGUAGES, ProductField.GENERIC_NAME_IN_LANGUAGES, ProductField.ABBREVIATED_NAME_IN_LANGUAGES, ProductField.INGREDIENTS_TEXT_IN_LANGUAGES, From 77fe7f3626cb59694b782ea06f0aebbaa2b85c21 Mon Sep 17 00:00:00 2001 From: Affan Date: Wed, 22 Jan 2025 15:21:21 +0530 Subject: [PATCH 02/10] Removed unwanted issues --- lib/src/model/product.dart | 20 -------------------- lib/src/utils/product_fields.dart | 26 ++------------------------ 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/lib/src/model/product.dart b/lib/src/model/product.dart index 9f720d8871..e0f2340937 100644 --- a/lib/src/model/product.dart +++ b/lib/src/model/product.dart @@ -109,32 +109,14 @@ class Product extends JsonObject { toJson: LanguageHelper.toJsonStringMap) Map? productNameInLanguages; - /// The conservation conditions of the product, either set directly or taken from one of the localizations. - /// - /// Prefer using [conservationConditionsInLanguages] for more accurate and localized data. - @JsonKey(name: 'conservation_conditions') - String? conservation_conditions; - /// Localized conservation conditions of the product, stored in a map where each language is represented by its respective key. - /// - /// This field is useful when you need to retrieve conservation conditions in a specific language. - /// For general usage, rely on [conservation_conditions] or the localization-specific fields. @JsonKey( name: 'conservation_conditions_in_languages', fromJson: LanguageHelper.fromJsonStringMap, toJson: LanguageHelper.toJsonStringMap) Map? conservationConditionsInLanguages; - /// The customer service information for the product, either set directly or taken from one of the localizations. - /// - /// Prefer using [customerServiceInLanguages] for more accurate and localized data. - @JsonKey(name: 'customer_service') - String? customer_service; - /// Localized customer service information for the product, stored in a map where each language is represented by its respective key. - /// - /// This field is useful when you need to retrieve customer service information in a specific language. - /// For general usage, rely on [customer_service] or the localization-specific fields. @JsonKey( name: 'customer_service_in_languages', fromJson: LanguageHelper.fromJsonStringMap, @@ -636,8 +618,6 @@ class Product extends JsonObject { {this.barcode, this.productName, this.productNameInLanguages, - this.conservation_conditions, - this.customer_service, this.genericName, this.brands, this.brandsTags, diff --git a/lib/src/utils/product_fields.dart b/lib/src/utils/product_fields.dart index 8bf6fd7154..54c2475ec1 100644 --- a/lib/src/utils/product_fields.dart +++ b/lib/src/utils/product_fields.dart @@ -18,34 +18,12 @@ enum ProductField implements OffTagged { inLanguagesProductField: ProductField.NAME_IN_LANGUAGES, isAllLanguages: true, ), - CONSERVATION_CONDITIONS( - offTag: 'conservation_conditions', - inLanguagesProductField: ProductField.CONSERVATION_CONDITIONS_IN_LANGUAGES, - ), - - CONSERVATION_CONDITIONS_IN_LANGUAGES( - offTag: 'conservation_conditions_', - isInLanguages: true, - ), - CONSERVATION_CONDITIONS_ALL_LANGUAGES( offTag: 'conservation_conditions_languages', - inLanguagesProductField: ProductField.CONSERVATION_CONDITIONS_IN_LANGUAGES, isAllLanguages: true, ), - CUSTOMER_SERVICE( - offTag: 'customer_service', - inLanguagesProductField: ProductField.CUSTOMER_SERVICE_IN_LANGUAGES, - ), - - CUSTOMER_SERVICE_IN_LANGUAGES( - offTag: 'customer_service_', - isInLanguages: true, - ), - CUSTOMER_SERVICE_ALL_LANGUAGES( offTag: 'customer_service_languages', - inLanguagesProductField: ProductField.CUSTOMER_SERVICE_IN_LANGUAGES, isAllLanguages: true, ), GENERIC_NAME( @@ -317,8 +295,6 @@ enum ProductField implements OffTagged { @Deprecated('Use ProductField.getInLanguagesList() instead') const Set fieldsInLanguages = { ProductField.NAME_IN_LANGUAGES, - ProductField.CONSERVATION_CONDITIONS_IN_LANGUAGES, - ProductField.CUSTOMER_SERVICE_IN_LANGUAGES, ProductField.GENERIC_NAME_IN_LANGUAGES, ProductField.ABBREVIATED_NAME_IN_LANGUAGES, ProductField.INGREDIENTS_TEXT_IN_LANGUAGES, @@ -342,6 +318,8 @@ const Set fieldsInLanguages = { @Deprecated('Use ProductField.getAllLanguagesList() instead') const Set fieldsAllLanguages = { ProductField.NAME_ALL_LANGUAGES, + ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES, + ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES, ProductField.GENERIC_NAME_ALL_LANGUAGES, ProductField.ABBREVIATED_NAME_ALL_LANGUAGES, ProductField.INGREDIENTS_TEXT_ALL_LANGUAGES, From 7050767177eddda0176a7fd23ab22ffe2a699f0b Mon Sep 17 00:00:00 2001 From: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com> Date: Thu, 23 Jan 2025 16:03:19 +0530 Subject: [PATCH 03/10] Update product.g.dart --- lib/src/model/product.g.dart | 324 ++++++++++++++++++++--------------- 1 file changed, 182 insertions(+), 142 deletions(-) diff --git a/lib/src/model/product.g.dart b/lib/src/model/product.g.dart index 1f3b609636..7ce53d3b14 100644 --- a/lib/src/model/product.g.dart +++ b/lib/src/model/product.g.dart @@ -103,6 +103,10 @@ Product _$ProductFromJson(Map json) => Product( ) ..productType = $enumDecodeNullable(_$ProductTypeEnumMap, json['product_type']) + ..conservationConditionsInLanguages = LanguageHelper.fromJsonStringMap( + json['conservation_conditions_in_languages']) + ..customerServiceInLanguages = LanguageHelper.fromJsonStringMap( + json['customer_service_in_languages']) ..genericNameInLanguages = LanguageHelper.fromJsonStringMap(json['generic_name_in_languages']) ..abbreviatedName = json['abbreviated_product_name'] as String? @@ -179,148 +183,184 @@ Product _$ProductFromJson(Map json) => Product( ..owner = json['owner'] as String? ..expirationDate = json['expiration_date'] as String?; -Map _$ProductToJson(Product instance) { - final val = { - 'code': instance.barcode, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('product_type', _$ProductTypeEnumMap[instance.productType]); - writeNotNull('product_name', instance.productName); - writeNotNull('product_name_in_languages', - LanguageHelper.toJsonStringMap(instance.productNameInLanguages)); - writeNotNull('generic_name', instance.genericName); - writeNotNull('generic_name_in_languages', - LanguageHelper.toJsonStringMap(instance.genericNameInLanguages)); - writeNotNull('abbreviated_product_name', instance.abbreviatedName); - writeNotNull('abbreviated_product_name_in_languages', - LanguageHelper.toJsonStringMap(instance.abbreviatedNameInLanguages)); - writeNotNull('brands', instance.brands); - writeNotNull('brands_tags', instance.brandsTags); - writeNotNull('brands_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.brandsTagsInLanguages)); - writeNotNull('countries', instance.countries); - writeNotNull('countries_tags', instance.countriesTags); - writeNotNull('countries_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.countriesTagsInLanguages)); - val['lang'] = LanguageHelper.toJson(instance.lang); - writeNotNull('quantity', instance.quantity); - writeNotNull('image_front_url', instance.imageFrontUrl); - writeNotNull('image_front_small_url', instance.imageFrontSmallUrl); - writeNotNull('image_ingredients_url', instance.imageIngredientsUrl); - writeNotNull( - 'image_ingredients_small_url', instance.imageIngredientsSmallUrl); - writeNotNull('image_nutrition_url', instance.imageNutritionUrl); - writeNotNull('image_nutrition_small_url', instance.imageNutritionSmallUrl); - writeNotNull('image_packaging_url', instance.imagePackagingUrl); - writeNotNull('image_packaging_small_url', instance.imagePackagingSmallUrl); - writeNotNull('serving_size', instance.servingSize); - writeNotNull('serving_quantity', instance.servingQuantity); - writeNotNull('product_quantity', instance.packagingQuantity); - val['selected_images'] = - JsonHelper.selectedImagesToJson(instance.selectedImages); - val['images'] = JsonHelper.allImagesToJson(instance.images); - writeNotNull( - 'ingredients', JsonHelper.ingredientsToJson(instance.ingredients)); - writeNotNull('ingredients_text', instance.ingredientsText); - writeNotNull('ingredients_text_in_languages', - LanguageHelper.toJsonStringMap(instance.ingredientsTextInLanguages)); - writeNotNull('ingredients_tags', instance.ingredientsTags); - writeNotNull('ingredients_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.ingredientsTagsInLanguages)); - val['imagesFreshnessInLanguages'] = instance.imagesFreshnessInLanguages?.map( - (k, e) => MapEntry(_$OpenFoodFactsLanguageEnumMap[k]!, - e.map((k, e) => MapEntry(_$ImageFieldEnumMap[k]!, e)))); - val['ingredients_analysis_tags'] = - IngredientsAnalysisTags.toJson(instance.ingredientsAnalysisTags); - writeNotNull( - 'ingredients_analysis_tags_in_languages', - LanguageHelper.toJsonStringsListMap( - instance.ingredientsAnalysisTagsInLanguages)); - writeNotNull('additives_tags', Additives.additivesToJson(instance.additives)); - writeNotNull('additives_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.additivesTagsInLanguages)); - writeNotNull('allergens_tags', Allergens.allergensToJson(instance.allergens)); - writeNotNull('allergens_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.allergensTagsInLanguages)); - writeNotNull( - 'nutrient_levels', NutrientLevels.toJson(instance.nutrientLevels)); - writeNotNull('nutriment_energy_unit', instance.nutrimentEnergyUnit); - val['nutrition_data'] = JsonHelper.checkboxToJSON(instance.nutritionData); - writeNotNull('nutrition_data_per', instance.nutrimentDataPer); - writeNotNull('nutrition_grade_fr', instance.nutriscore); - writeNotNull('compared_to_category', instance.comparedToCategory); - writeNotNull('categories', instance.categories); - writeNotNull('categories_tags', instance.categoriesTags); - writeNotNull('categories_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.categoriesTagsInLanguages)); - writeNotNull('labels', instance.labels); - writeNotNull('labels_tags', instance.labelsTags); - writeNotNull('labels_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.labelsTagsInLanguages)); - writeNotNull('packaging', instance.packaging); - writeNotNull( - 'packagings', JsonHelper.productPackagingsToJson(instance.packagings)); - val['packagings_complete'] = - JsonHelper.boolToJSON(instance.packagingsComplete); - writeNotNull('packaging_tags', instance.packagingTags); - writeNotNull('packaging_text_in_languages', - LanguageHelper.toJsonStringMap(instance.packagingTextInLanguages)); - writeNotNull('misc_tags', instance.miscTags); - writeNotNull('misc_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.miscTagsInLanguages)); - writeNotNull('states_tags', instance.statesTags); - writeNotNull('states_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.statesTagsInLanguages)); - writeNotNull('traces_tags', instance.tracesTags); - writeNotNull('traces_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.tracesTagsInLanguages)); - writeNotNull('stores_tags', instance.storesTags); - writeNotNull('stores_tags_in_languages', - LanguageHelper.toJsonStringsListMap(instance.storesTagsInLanguages)); - writeNotNull('stores', instance.stores); - writeNotNull('attribute_groups', - JsonHelper.attributeGroupsToJson(instance.attributeGroups)); - writeNotNull( - 'last_modified_t', JsonHelper.dateToTimestamp(instance.lastModified)); - writeNotNull('last_modified_by', instance.lastModifiedBy); - writeNotNull('last_image_t', JsonHelper.dateToTimestamp(instance.lastImage)); - writeNotNull('last_editor', instance.lastEditor); - writeNotNull('entry_dates_tags', instance.entryDates); - writeNotNull('last_check_dates_tags', instance.lastCheckDates); - writeNotNull('last_edit_dates_tags', instance.lastEditDates); - writeNotNull('last_image_dates_tags', instance.lastImageDates); - writeNotNull( - 'last_checked_t', JsonHelper.dateToTimestamp(instance.lastChecked)); - writeNotNull('last_checker', instance.lastChecker); - writeNotNull('created_t', JsonHelper.dateToTimestamp(instance.created)); - writeNotNull('creator', instance.creator); - writeNotNull('editors_tags', instance.editors); - writeNotNull('ecoscore_grade', instance.ecoscoreGrade); - writeNotNull('ecoscore_score', instance.ecoscoreScore); - writeNotNull( - 'ecoscore_data', EcoscoreData.toJsonHelper(instance.ecoscoreData)); - writeNotNull('knowledge_panels', - KnowledgePanels.toJsonHelper(instance.knowledgePanels)); - writeNotNull('emb_codes', instance.embCodes); - writeNotNull('manufacturing_places', instance.manufacturingPlaces); - writeNotNull('origins', instance.origins); - writeNotNull('nova_group', instance.novaGroup); - writeNotNull('link', instance.website); - val['obsolete'] = JsonHelper.checkboxToJSON(instance.obsolete); - writeNotNull('owner_fields', instance.ownerFields); - writeNotNull('owner', instance.owner); - writeNotNull('expiration_date', instance.expirationDate); - val['no_nutrition_data'] = - JsonHelper.checkboxToJSON(instance.noNutritionData); - val['nutriments'] = Nutriments.toJsonHelper(instance.nutriments); - return val; -} +Map _$ProductToJson(Product instance) => { + 'code': instance.barcode, + if (_$ProductTypeEnumMap[instance.productType] case final value?) + 'product_type': value, + if (instance.productName case final value?) 'product_name': value, + if (LanguageHelper.toJsonStringMap(instance.productNameInLanguages) + case final value?) + 'product_name_in_languages': value, + if (LanguageHelper.toJsonStringMap( + instance.conservationConditionsInLanguages) + case final value?) + 'conservation_conditions_in_languages': value, + if (LanguageHelper.toJsonStringMap(instance.customerServiceInLanguages) + case final value?) + 'customer_service_in_languages': value, + if (instance.genericName case final value?) 'generic_name': value, + if (LanguageHelper.toJsonStringMap(instance.genericNameInLanguages) + case final value?) + 'generic_name_in_languages': value, + if (instance.abbreviatedName case final value?) + 'abbreviated_product_name': value, + if (LanguageHelper.toJsonStringMap(instance.abbreviatedNameInLanguages) + case final value?) + 'abbreviated_product_name_in_languages': value, + if (instance.brands case final value?) 'brands': value, + if (instance.brandsTags case final value?) 'brands_tags': value, + if (LanguageHelper.toJsonStringsListMap(instance.brandsTagsInLanguages) + case final value?) + 'brands_tags_in_languages': value, + if (instance.countries case final value?) 'countries': value, + if (instance.countriesTags case final value?) 'countries_tags': value, + if (LanguageHelper.toJsonStringsListMap(instance.countriesTagsInLanguages) + case final value?) + 'countries_tags_in_languages': value, + 'lang': LanguageHelper.toJson(instance.lang), + if (instance.quantity case final value?) 'quantity': value, + if (instance.imageFrontUrl case final value?) 'image_front_url': value, + if (instance.imageFrontSmallUrl case final value?) + 'image_front_small_url': value, + if (instance.imageIngredientsUrl case final value?) + 'image_ingredients_url': value, + if (instance.imageIngredientsSmallUrl case final value?) + 'image_ingredients_small_url': value, + if (instance.imageNutritionUrl case final value?) + 'image_nutrition_url': value, + if (instance.imageNutritionSmallUrl case final value?) + 'image_nutrition_small_url': value, + if (instance.imagePackagingUrl case final value?) + 'image_packaging_url': value, + if (instance.imagePackagingSmallUrl case final value?) + 'image_packaging_small_url': value, + if (instance.servingSize case final value?) 'serving_size': value, + if (instance.servingQuantity case final value?) 'serving_quantity': value, + if (instance.packagingQuantity case final value?) + 'product_quantity': value, + 'selected_images': + JsonHelper.selectedImagesToJson(instance.selectedImages), + 'images': JsonHelper.allImagesToJson(instance.images), + if (JsonHelper.ingredientsToJson(instance.ingredients) case final value?) + 'ingredients': value, + if (instance.ingredientsText case final value?) 'ingredients_text': value, + if (LanguageHelper.toJsonStringMap(instance.ingredientsTextInLanguages) + case final value?) + 'ingredients_text_in_languages': value, + if (instance.ingredientsTags case final value?) 'ingredients_tags': value, + if (LanguageHelper.toJsonStringsListMap( + instance.ingredientsTagsInLanguages) + case final value?) + 'ingredients_tags_in_languages': value, + 'imagesFreshnessInLanguages': instance.imagesFreshnessInLanguages?.map( + (k, e) => MapEntry(_$OpenFoodFactsLanguageEnumMap[k]!, + e.map((k, e) => MapEntry(_$ImageFieldEnumMap[k]!, e)))), + 'ingredients_analysis_tags': + IngredientsAnalysisTags.toJson(instance.ingredientsAnalysisTags), + if (LanguageHelper.toJsonStringsListMap( + instance.ingredientsAnalysisTagsInLanguages) + case final value?) + 'ingredients_analysis_tags_in_languages': value, + if (Additives.additivesToJson(instance.additives) case final value?) + 'additives_tags': value, + if (LanguageHelper.toJsonStringsListMap(instance.additivesTagsInLanguages) + case final value?) + 'additives_tags_in_languages': value, + if (Allergens.allergensToJson(instance.allergens) case final value?) + 'allergens_tags': value, + if (LanguageHelper.toJsonStringsListMap(instance.allergensTagsInLanguages) + case final value?) + 'allergens_tags_in_languages': value, + if (NutrientLevels.toJson(instance.nutrientLevels) case final value?) + 'nutrient_levels': value, + if (instance.nutrimentEnergyUnit case final value?) + 'nutriment_energy_unit': value, + 'nutrition_data': JsonHelper.checkboxToJSON(instance.nutritionData), + if (instance.nutrimentDataPer case final value?) + 'nutrition_data_per': value, + if (instance.nutriscore case final value?) 'nutrition_grade_fr': value, + if (instance.comparedToCategory case final value?) + 'compared_to_category': value, + if (instance.categories case final value?) 'categories': value, + if (instance.categoriesTags case final value?) 'categories_tags': value, + if (LanguageHelper.toJsonStringsListMap( + instance.categoriesTagsInLanguages) + case final value?) + 'categories_tags_in_languages': value, + if (instance.labels case final value?) 'labels': value, + if (instance.labelsTags case final value?) 'labels_tags': value, + if (LanguageHelper.toJsonStringsListMap(instance.labelsTagsInLanguages) + case final value?) + 'labels_tags_in_languages': value, + if (instance.packaging case final value?) 'packaging': value, + if (JsonHelper.productPackagingsToJson(instance.packagings) + case final value?) + 'packagings': value, + 'packagings_complete': JsonHelper.boolToJSON(instance.packagingsComplete), + if (instance.packagingTags case final value?) 'packaging_tags': value, + if (LanguageHelper.toJsonStringMap(instance.packagingTextInLanguages) + case final value?) + 'packaging_text_in_languages': value, + if (instance.miscTags case final value?) 'misc_tags': value, + if (LanguageHelper.toJsonStringsListMap(instance.miscTagsInLanguages) + case final value?) + 'misc_tags_in_languages': value, + if (instance.statesTags case final value?) 'states_tags': value, + if (LanguageHelper.toJsonStringsListMap(instance.statesTagsInLanguages) + case final value?) + 'states_tags_in_languages': value, + if (instance.tracesTags case final value?) 'traces_tags': value, + if (LanguageHelper.toJsonStringsListMap(instance.tracesTagsInLanguages) + case final value?) + 'traces_tags_in_languages': value, + if (instance.storesTags case final value?) 'stores_tags': value, + if (LanguageHelper.toJsonStringsListMap(instance.storesTagsInLanguages) + case final value?) + 'stores_tags_in_languages': value, + if (instance.stores case final value?) 'stores': value, + if (JsonHelper.attributeGroupsToJson(instance.attributeGroups) + case final value?) + 'attribute_groups': value, + if (JsonHelper.dateToTimestamp(instance.lastModified) case final value?) + 'last_modified_t': value, + if (instance.lastModifiedBy case final value?) 'last_modified_by': value, + if (JsonHelper.dateToTimestamp(instance.lastImage) case final value?) + 'last_image_t': value, + if (instance.lastEditor case final value?) 'last_editor': value, + if (instance.entryDates case final value?) 'entry_dates_tags': value, + if (instance.lastCheckDates case final value?) + 'last_check_dates_tags': value, + if (instance.lastEditDates case final value?) + 'last_edit_dates_tags': value, + if (instance.lastImageDates case final value?) + 'last_image_dates_tags': value, + if (JsonHelper.dateToTimestamp(instance.lastChecked) case final value?) + 'last_checked_t': value, + if (instance.lastChecker case final value?) 'last_checker': value, + if (JsonHelper.dateToTimestamp(instance.created) case final value?) + 'created_t': value, + if (instance.creator case final value?) 'creator': value, + if (instance.editors case final value?) 'editors_tags': value, + if (instance.ecoscoreGrade case final value?) 'ecoscore_grade': value, + if (instance.ecoscoreScore case final value?) 'ecoscore_score': value, + if (EcoscoreData.toJsonHelper(instance.ecoscoreData) case final value?) + 'ecoscore_data': value, + if (KnowledgePanels.toJsonHelper(instance.knowledgePanels) + case final value?) + 'knowledge_panels': value, + if (instance.embCodes case final value?) 'emb_codes': value, + if (instance.manufacturingPlaces case final value?) + 'manufacturing_places': value, + if (instance.origins case final value?) 'origins': value, + if (instance.novaGroup case final value?) 'nova_group': value, + if (instance.website case final value?) 'link': value, + 'obsolete': JsonHelper.checkboxToJSON(instance.obsolete), + if (instance.ownerFields case final value?) 'owner_fields': value, + if (instance.owner case final value?) 'owner': value, + if (instance.expirationDate case final value?) 'expiration_date': value, + 'no_nutrition_data': JsonHelper.checkboxToJSON(instance.noNutritionData), + 'nutriments': Nutriments.toJsonHelper(instance.nutriments), + }; const _$ProductTypeEnumMap = { ProductType.food: 'food', From 936a9caae89b40fc2b90a214b4e9de25bff7473a Mon Sep 17 00:00:00 2001 From: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com> Date: Thu, 23 Jan 2025 21:31:56 +0530 Subject: [PATCH 04/10] Update product.g.dart --- lib/src/model/product.g.dart | 326 ++++++++++++++++------------------- 1 file changed, 148 insertions(+), 178 deletions(-) diff --git a/lib/src/model/product.g.dart b/lib/src/model/product.g.dart index 7ce53d3b14..fcef642a4f 100644 --- a/lib/src/model/product.g.dart +++ b/lib/src/model/product.g.dart @@ -183,184 +183,154 @@ Product _$ProductFromJson(Map json) => Product( ..owner = json['owner'] as String? ..expirationDate = json['expiration_date'] as String?; -Map _$ProductToJson(Product instance) => { - 'code': instance.barcode, - if (_$ProductTypeEnumMap[instance.productType] case final value?) - 'product_type': value, - if (instance.productName case final value?) 'product_name': value, - if (LanguageHelper.toJsonStringMap(instance.productNameInLanguages) - case final value?) - 'product_name_in_languages': value, - if (LanguageHelper.toJsonStringMap( - instance.conservationConditionsInLanguages) - case final value?) - 'conservation_conditions_in_languages': value, - if (LanguageHelper.toJsonStringMap(instance.customerServiceInLanguages) - case final value?) - 'customer_service_in_languages': value, - if (instance.genericName case final value?) 'generic_name': value, - if (LanguageHelper.toJsonStringMap(instance.genericNameInLanguages) - case final value?) - 'generic_name_in_languages': value, - if (instance.abbreviatedName case final value?) - 'abbreviated_product_name': value, - if (LanguageHelper.toJsonStringMap(instance.abbreviatedNameInLanguages) - case final value?) - 'abbreviated_product_name_in_languages': value, - if (instance.brands case final value?) 'brands': value, - if (instance.brandsTags case final value?) 'brands_tags': value, - if (LanguageHelper.toJsonStringsListMap(instance.brandsTagsInLanguages) - case final value?) - 'brands_tags_in_languages': value, - if (instance.countries case final value?) 'countries': value, - if (instance.countriesTags case final value?) 'countries_tags': value, - if (LanguageHelper.toJsonStringsListMap(instance.countriesTagsInLanguages) - case final value?) - 'countries_tags_in_languages': value, - 'lang': LanguageHelper.toJson(instance.lang), - if (instance.quantity case final value?) 'quantity': value, - if (instance.imageFrontUrl case final value?) 'image_front_url': value, - if (instance.imageFrontSmallUrl case final value?) - 'image_front_small_url': value, - if (instance.imageIngredientsUrl case final value?) - 'image_ingredients_url': value, - if (instance.imageIngredientsSmallUrl case final value?) - 'image_ingredients_small_url': value, - if (instance.imageNutritionUrl case final value?) - 'image_nutrition_url': value, - if (instance.imageNutritionSmallUrl case final value?) - 'image_nutrition_small_url': value, - if (instance.imagePackagingUrl case final value?) - 'image_packaging_url': value, - if (instance.imagePackagingSmallUrl case final value?) - 'image_packaging_small_url': value, - if (instance.servingSize case final value?) 'serving_size': value, - if (instance.servingQuantity case final value?) 'serving_quantity': value, - if (instance.packagingQuantity case final value?) - 'product_quantity': value, - 'selected_images': - JsonHelper.selectedImagesToJson(instance.selectedImages), - 'images': JsonHelper.allImagesToJson(instance.images), - if (JsonHelper.ingredientsToJson(instance.ingredients) case final value?) - 'ingredients': value, - if (instance.ingredientsText case final value?) 'ingredients_text': value, - if (LanguageHelper.toJsonStringMap(instance.ingredientsTextInLanguages) - case final value?) - 'ingredients_text_in_languages': value, - if (instance.ingredientsTags case final value?) 'ingredients_tags': value, - if (LanguageHelper.toJsonStringsListMap( - instance.ingredientsTagsInLanguages) - case final value?) - 'ingredients_tags_in_languages': value, - 'imagesFreshnessInLanguages': instance.imagesFreshnessInLanguages?.map( - (k, e) => MapEntry(_$OpenFoodFactsLanguageEnumMap[k]!, - e.map((k, e) => MapEntry(_$ImageFieldEnumMap[k]!, e)))), - 'ingredients_analysis_tags': - IngredientsAnalysisTags.toJson(instance.ingredientsAnalysisTags), - if (LanguageHelper.toJsonStringsListMap( - instance.ingredientsAnalysisTagsInLanguages) - case final value?) - 'ingredients_analysis_tags_in_languages': value, - if (Additives.additivesToJson(instance.additives) case final value?) - 'additives_tags': value, - if (LanguageHelper.toJsonStringsListMap(instance.additivesTagsInLanguages) - case final value?) - 'additives_tags_in_languages': value, - if (Allergens.allergensToJson(instance.allergens) case final value?) - 'allergens_tags': value, - if (LanguageHelper.toJsonStringsListMap(instance.allergensTagsInLanguages) - case final value?) - 'allergens_tags_in_languages': value, - if (NutrientLevels.toJson(instance.nutrientLevels) case final value?) - 'nutrient_levels': value, - if (instance.nutrimentEnergyUnit case final value?) - 'nutriment_energy_unit': value, - 'nutrition_data': JsonHelper.checkboxToJSON(instance.nutritionData), - if (instance.nutrimentDataPer case final value?) - 'nutrition_data_per': value, - if (instance.nutriscore case final value?) 'nutrition_grade_fr': value, - if (instance.comparedToCategory case final value?) - 'compared_to_category': value, - if (instance.categories case final value?) 'categories': value, - if (instance.categoriesTags case final value?) 'categories_tags': value, - if (LanguageHelper.toJsonStringsListMap( - instance.categoriesTagsInLanguages) - case final value?) - 'categories_tags_in_languages': value, - if (instance.labels case final value?) 'labels': value, - if (instance.labelsTags case final value?) 'labels_tags': value, - if (LanguageHelper.toJsonStringsListMap(instance.labelsTagsInLanguages) - case final value?) - 'labels_tags_in_languages': value, - if (instance.packaging case final value?) 'packaging': value, - if (JsonHelper.productPackagingsToJson(instance.packagings) - case final value?) - 'packagings': value, - 'packagings_complete': JsonHelper.boolToJSON(instance.packagingsComplete), - if (instance.packagingTags case final value?) 'packaging_tags': value, - if (LanguageHelper.toJsonStringMap(instance.packagingTextInLanguages) - case final value?) - 'packaging_text_in_languages': value, - if (instance.miscTags case final value?) 'misc_tags': value, - if (LanguageHelper.toJsonStringsListMap(instance.miscTagsInLanguages) - case final value?) - 'misc_tags_in_languages': value, - if (instance.statesTags case final value?) 'states_tags': value, - if (LanguageHelper.toJsonStringsListMap(instance.statesTagsInLanguages) - case final value?) - 'states_tags_in_languages': value, - if (instance.tracesTags case final value?) 'traces_tags': value, - if (LanguageHelper.toJsonStringsListMap(instance.tracesTagsInLanguages) - case final value?) - 'traces_tags_in_languages': value, - if (instance.storesTags case final value?) 'stores_tags': value, - if (LanguageHelper.toJsonStringsListMap(instance.storesTagsInLanguages) - case final value?) - 'stores_tags_in_languages': value, - if (instance.stores case final value?) 'stores': value, - if (JsonHelper.attributeGroupsToJson(instance.attributeGroups) - case final value?) - 'attribute_groups': value, - if (JsonHelper.dateToTimestamp(instance.lastModified) case final value?) - 'last_modified_t': value, - if (instance.lastModifiedBy case final value?) 'last_modified_by': value, - if (JsonHelper.dateToTimestamp(instance.lastImage) case final value?) - 'last_image_t': value, - if (instance.lastEditor case final value?) 'last_editor': value, - if (instance.entryDates case final value?) 'entry_dates_tags': value, - if (instance.lastCheckDates case final value?) - 'last_check_dates_tags': value, - if (instance.lastEditDates case final value?) - 'last_edit_dates_tags': value, - if (instance.lastImageDates case final value?) - 'last_image_dates_tags': value, - if (JsonHelper.dateToTimestamp(instance.lastChecked) case final value?) - 'last_checked_t': value, - if (instance.lastChecker case final value?) 'last_checker': value, - if (JsonHelper.dateToTimestamp(instance.created) case final value?) - 'created_t': value, - if (instance.creator case final value?) 'creator': value, - if (instance.editors case final value?) 'editors_tags': value, - if (instance.ecoscoreGrade case final value?) 'ecoscore_grade': value, - if (instance.ecoscoreScore case final value?) 'ecoscore_score': value, - if (EcoscoreData.toJsonHelper(instance.ecoscoreData) case final value?) - 'ecoscore_data': value, - if (KnowledgePanels.toJsonHelper(instance.knowledgePanels) - case final value?) - 'knowledge_panels': value, - if (instance.embCodes case final value?) 'emb_codes': value, - if (instance.manufacturingPlaces case final value?) - 'manufacturing_places': value, - if (instance.origins case final value?) 'origins': value, - if (instance.novaGroup case final value?) 'nova_group': value, - if (instance.website case final value?) 'link': value, - 'obsolete': JsonHelper.checkboxToJSON(instance.obsolete), - if (instance.ownerFields case final value?) 'owner_fields': value, - if (instance.owner case final value?) 'owner': value, - if (instance.expirationDate case final value?) 'expiration_date': value, - 'no_nutrition_data': JsonHelper.checkboxToJSON(instance.noNutritionData), - 'nutriments': Nutriments.toJsonHelper(instance.nutriments), - }; +Map _$ProductToJson(Product instance) { + final val = { + 'code': instance.barcode, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('product_type', _$ProductTypeEnumMap[instance.productType]); + writeNotNull('product_name', instance.productName); + writeNotNull('product_name_in_languages', + LanguageHelper.toJsonStringMap(instance.productNameInLanguages)); + writeNotNull( + 'conservation_conditions_in_languages', + LanguageHelper.toJsonStringMap( + instance.conservationConditionsInLanguages)); + writeNotNull('customer_service_in_languages', + LanguageHelper.toJsonStringMap(instance.customerServiceInLanguages)); + writeNotNull('generic_name', instance.genericName); + writeNotNull('generic_name_in_languages', + LanguageHelper.toJsonStringMap(instance.genericNameInLanguages)); + writeNotNull('abbreviated_product_name', instance.abbreviatedName); + writeNotNull('abbreviated_product_name_in_languages', + LanguageHelper.toJsonStringMap(instance.abbreviatedNameInLanguages)); + writeNotNull('brands', instance.brands); + writeNotNull('brands_tags', instance.brandsTags); + writeNotNull('brands_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.brandsTagsInLanguages)); + writeNotNull('countries', instance.countries); + writeNotNull('countries_tags', instance.countriesTags); + writeNotNull('countries_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.countriesTagsInLanguages)); + val['lang'] = LanguageHelper.toJson(instance.lang); + writeNotNull('quantity', instance.quantity); + writeNotNull('image_front_url', instance.imageFrontUrl); + writeNotNull('image_front_small_url', instance.imageFrontSmallUrl); + writeNotNull('image_ingredients_url', instance.imageIngredientsUrl); + writeNotNull( + 'image_ingredients_small_url', instance.imageIngredientsSmallUrl); + writeNotNull('image_nutrition_url', instance.imageNutritionUrl); + writeNotNull('image_nutrition_small_url', instance.imageNutritionSmallUrl); + writeNotNull('image_packaging_url', instance.imagePackagingUrl); + writeNotNull('image_packaging_small_url', instance.imagePackagingSmallUrl); + writeNotNull('serving_size', instance.servingSize); + writeNotNull('serving_quantity', instance.servingQuantity); + writeNotNull('product_quantity', instance.packagingQuantity); + val['selected_images'] = + JsonHelper.selectedImagesToJson(instance.selectedImages); + val['images'] = JsonHelper.allImagesToJson(instance.images); + writeNotNull( + 'ingredients', JsonHelper.ingredientsToJson(instance.ingredients)); + writeNotNull('ingredients_text', instance.ingredientsText); + writeNotNull('ingredients_text_in_languages', + LanguageHelper.toJsonStringMap(instance.ingredientsTextInLanguages)); + writeNotNull('ingredients_tags', instance.ingredientsTags); + writeNotNull('ingredients_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.ingredientsTagsInLanguages)); + val['imagesFreshnessInLanguages'] = instance.imagesFreshnessInLanguages?.map( + (k, e) => MapEntry(_$OpenFoodFactsLanguageEnumMap[k]!, + e.map((k, e) => MapEntry(_$ImageFieldEnumMap[k]!, e)))); + val['ingredients_analysis_tags'] = + IngredientsAnalysisTags.toJson(instance.ingredientsAnalysisTags); + writeNotNull( + 'ingredients_analysis_tags_in_languages', + LanguageHelper.toJsonStringsListMap( + instance.ingredientsAnalysisTagsInLanguages)); + writeNotNull('additives_tags', Additives.additivesToJson(instance.additives)); + writeNotNull('additives_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.additivesTagsInLanguages)); + writeNotNull('allergens_tags', Allergens.allergensToJson(instance.allergens)); + writeNotNull('allergens_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.allergensTagsInLanguages)); + writeNotNull( + 'nutrient_levels', NutrientLevels.toJson(instance.nutrientLevels)); + writeNotNull('nutriment_energy_unit', instance.nutrimentEnergyUnit); + val['nutrition_data'] = JsonHelper.checkboxToJSON(instance.nutritionData); + writeNotNull('nutrition_data_per', instance.nutrimentDataPer); + writeNotNull('nutrition_grade_fr', instance.nutriscore); + writeNotNull('compared_to_category', instance.comparedToCategory); + writeNotNull('categories', instance.categories); + writeNotNull('categories_tags', instance.categoriesTags); + writeNotNull('categories_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.categoriesTagsInLanguages)); + writeNotNull('labels', instance.labels); + writeNotNull('labels_tags', instance.labelsTags); + writeNotNull('labels_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.labelsTagsInLanguages)); + writeNotNull('packaging', instance.packaging); + writeNotNull( + 'packagings', JsonHelper.productPackagingsToJson(instance.packagings)); + val['packagings_complete'] = + JsonHelper.boolToJSON(instance.packagingsComplete); + writeNotNull('packaging_tags', instance.packagingTags); + writeNotNull('packaging_text_in_languages', + LanguageHelper.toJsonStringMap(instance.packagingTextInLanguages)); + writeNotNull('misc_tags', instance.miscTags); + writeNotNull('misc_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.miscTagsInLanguages)); + writeNotNull('states_tags', instance.statesTags); + writeNotNull('states_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.statesTagsInLanguages)); + writeNotNull('traces_tags', instance.tracesTags); + writeNotNull('traces_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.tracesTagsInLanguages)); + writeNotNull('stores_tags', instance.storesTags); + writeNotNull('stores_tags_in_languages', + LanguageHelper.toJsonStringsListMap(instance.storesTagsInLanguages)); + writeNotNull('stores', instance.stores); + writeNotNull('attribute_groups', + JsonHelper.attributeGroupsToJson(instance.attributeGroups)); + writeNotNull( + 'last_modified_t', JsonHelper.dateToTimestamp(instance.lastModified)); + writeNotNull('last_modified_by', instance.lastModifiedBy); + writeNotNull('last_image_t', JsonHelper.dateToTimestamp(instance.lastImage)); + writeNotNull('last_editor', instance.lastEditor); + writeNotNull('entry_dates_tags', instance.entryDates); + writeNotNull('last_check_dates_tags', instance.lastCheckDates); + writeNotNull('last_edit_dates_tags', instance.lastEditDates); + writeNotNull('last_image_dates_tags', instance.lastImageDates); + writeNotNull( + 'last_checked_t', JsonHelper.dateToTimestamp(instance.lastChecked)); + writeNotNull('last_checker', instance.lastChecker); + writeNotNull('created_t', JsonHelper.dateToTimestamp(instance.created)); + writeNotNull('creator', instance.creator); + writeNotNull('editors_tags', instance.editors); + writeNotNull('ecoscore_grade', instance.ecoscoreGrade); + writeNotNull('ecoscore_score', instance.ecoscoreScore); + writeNotNull( + 'ecoscore_data', EcoscoreData.toJsonHelper(instance.ecoscoreData)); + writeNotNull('knowledge_panels', + KnowledgePanels.toJsonHelper(instance.knowledgePanels)); + writeNotNull('emb_codes', instance.embCodes); + writeNotNull('manufacturing_places', instance.manufacturingPlaces); + writeNotNull('origins', instance.origins); + writeNotNull('nova_group', instance.novaGroup); + writeNotNull('link', instance.website); + val['obsolete'] = JsonHelper.checkboxToJSON(instance.obsolete); + writeNotNull('owner_fields', instance.ownerFields); + writeNotNull('owner', instance.owner); + writeNotNull('expiration_date', instance.expirationDate); + val['no_nutrition_data'] = + JsonHelper.checkboxToJSON(instance.noNutritionData); + val['nutriments'] = Nutriments.toJsonHelper(instance.nutriments); + return val; +} const _$ProductTypeEnumMap = { ProductType.food: 'food', From 984fbcaa5b9993dac64077f191885c42b12689a5 Mon Sep 17 00:00:00 2001 From: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:14:38 +0000 Subject: [PATCH 05/10] added test --- test/api_get_product_test.dart | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/api_get_product_test.dart b/test/api_get_product_test.dart index 5b1b9821c7..4302ad5f46 100644 --- a/test/api_get_product_test.dart +++ b/test/api_get_product_test.dart @@ -232,6 +232,33 @@ void main() { expect(nutriments.getValue(Nutrient.iron, perSize), 0.00041); expect(nutriments.getValue(Nutrient.vitaminC, perSize), 0.0339); }); + + test('get localized conservation conditions and customer service', () async { + ProductQueryConfiguration configuration = ProductQueryConfiguration( + '3017620425035', // Using an existing product barcode from previous tests + fields: [ + ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES, + ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES, + ], + version: ProductQueryVersion.v3, + ); + ProductResultV3 result = await getProductV3InProd( + configuration, + ); + + expect(result.status, ProductResultV3.statusSuccess); + expect(result.product, isNotNull); + + // Check conservation conditions in languages + expect(result.product!.conservationConditionsInLanguages, isNotNull); + expect(result.product!.conservationConditionsInLanguages, isNotEmpty); + expect(result.product!.conservationConditionsInLanguages!.containsKey(OpenFoodFactsLanguage.FRENCH), isTrue); + + // Check customer service in languages + expect(result.product!.customerServiceInLanguages, isNotNull); + expect(result.product!.customerServiceInLanguages, isNotEmpty); + expect(result.product!.customerServiceInLanguages!.containsKey(OpenFoodFactsLanguage.FRENCH), isTrue); + }); test('get uncommon nutrients', () async { // PROD data as of 2021-07-16 From 6e1298fad98140bfe00b6eb8ecc3e2f5c559ef42 Mon Sep 17 00:00:00 2001 From: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com> Date: Fri, 24 Jan 2025 17:56:32 +0530 Subject: [PATCH 06/10] Update api_get_product_test.dart --- test/api_get_product_test.dart | 59 ++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/test/api_get_product_test.dart b/test/api_get_product_test.dart index 4302ad5f46..ca367e8c49 100644 --- a/test/api_get_product_test.dart +++ b/test/api_get_product_test.dart @@ -234,32 +234,41 @@ void main() { }); test('get localized conservation conditions and customer service', () async { - ProductQueryConfiguration configuration = ProductQueryConfiguration( - '3017620425035', // Using an existing product barcode from previous tests - fields: [ - ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES, - ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES, - ], - version: ProductQueryVersion.v3, - ); - ProductResultV3 result = await getProductV3InProd( - configuration, - ); - - expect(result.status, ProductResultV3.statusSuccess); - expect(result.product, isNotNull); - - // Check conservation conditions in languages - expect(result.product!.conservationConditionsInLanguages, isNotNull); - expect(result.product!.conservationConditionsInLanguages, isNotEmpty); - expect(result.product!.conservationConditionsInLanguages!.containsKey(OpenFoodFactsLanguage.FRENCH), isTrue); - - // Check customer service in languages - expect(result.product!.customerServiceInLanguages, isNotNull); - expect(result.product!.customerServiceInLanguages, isNotEmpty); - expect(result.product!.customerServiceInLanguages!.containsKey(OpenFoodFactsLanguage.FRENCH), isTrue); + ProductQueryConfiguration configuration = ProductQueryConfiguration( + '3017620425035', + fields: [ + ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES, + ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES, + ], + version: ProductQueryVersion.v3, + language: OpenFoodFactsLanguage.ALL_LANGUAGES, + ); + + ProductResultV3 result = await getProductV3InProd(configuration); + + expect(result.status, ProductResultV3.statusSuccess); + expect(result.product, isNotNull); + + final conservationConditions = result.product!.conservationConditionsInLanguages; + expect(conservationConditions, isNotNull); + expect(conservationConditions, isNotEmpty); + expect(conservationConditions!.containsKey(OpenFoodFactsLanguage.ALL_LANGUAGES), isTrue); + expect(conservationConditions[OpenFoodFactsLanguage.ALL_LANGUAGES], isNotEmpty); + expect( + conservationConditions[OpenFoodFactsLanguage.ALL_LANGUAGES], + isA().having((s) => s.trim().isNotEmpty, 'non-empty string', isTrue), + ); + + final customerService = result.product!.customerServiceInLanguages; + expect(customerService, isNotNull); + expect(customerService, isNotEmpty); + expect(customerService!.containsKey(OpenFoodFactsLanguage.ALL_LANGUAGES), isTrue); + expect(customerService[OpenFoodFactsLanguage.ALL_LANGUAGES], isNotEmpty); + expect( + customerService[OpenFoodFactsLanguage.ALL_LANGUAGES], + isA().having((s) => s.trim().isNotEmpty, 'non-empty string', isTrue), + ); }); - test('get uncommon nutrients', () async { // PROD data as of 2021-07-16 const OpenFoodFactsLanguage language = OpenFoodFactsLanguage.FRENCH; From 96e1aeb7dcce6bc7fc0ca9241f1f15a5a88753ee Mon Sep 17 00:00:00 2001 From: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com> Date: Fri, 24 Jan 2025 17:02:50 +0000 Subject: [PATCH 07/10] formatted using dart format --- test/api_get_product_test.dart | 81 +++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/test/api_get_product_test.dart b/test/api_get_product_test.dart index ca367e8c49..5991c9f9ba 100644 --- a/test/api_get_product_test.dart +++ b/test/api_get_product_test.dart @@ -232,42 +232,51 @@ void main() { expect(nutriments.getValue(Nutrient.iron, perSize), 0.00041); expect(nutriments.getValue(Nutrient.vitaminC, perSize), 0.0339); }); - - test('get localized conservation conditions and customer service', () async { - ProductQueryConfiguration configuration = ProductQueryConfiguration( - '3017620425035', - fields: [ - ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES, - ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES, - ], - version: ProductQueryVersion.v3, - language: OpenFoodFactsLanguage.ALL_LANGUAGES, - ); - - ProductResultV3 result = await getProductV3InProd(configuration); - - expect(result.status, ProductResultV3.statusSuccess); - expect(result.product, isNotNull); - - final conservationConditions = result.product!.conservationConditionsInLanguages; - expect(conservationConditions, isNotNull); - expect(conservationConditions, isNotEmpty); - expect(conservationConditions!.containsKey(OpenFoodFactsLanguage.ALL_LANGUAGES), isTrue); - expect(conservationConditions[OpenFoodFactsLanguage.ALL_LANGUAGES], isNotEmpty); - expect( - conservationConditions[OpenFoodFactsLanguage.ALL_LANGUAGES], - isA().having((s) => s.trim().isNotEmpty, 'non-empty string', isTrue), - ); - - final customerService = result.product!.customerServiceInLanguages; - expect(customerService, isNotNull); - expect(customerService, isNotEmpty); - expect(customerService!.containsKey(OpenFoodFactsLanguage.ALL_LANGUAGES), isTrue); - expect(customerService[OpenFoodFactsLanguage.ALL_LANGUAGES], isNotEmpty); - expect( - customerService[OpenFoodFactsLanguage.ALL_LANGUAGES], - isA().having((s) => s.trim().isNotEmpty, 'non-empty string', isTrue), - ); + + test('get localized conservation conditions and customer service', + () async { + ProductQueryConfiguration configuration = ProductQueryConfiguration( + '3017620425035', + fields: [ + ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES, + ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES, + ], + version: ProductQueryVersion.v3, + language: OpenFoodFactsLanguage.ALL_LANGUAGES, + ); + + ProductResultV3 result = await getProductV3InProd(configuration); + + expect(result.status, ProductResultV3.statusSuccess); + expect(result.product, isNotNull); + + final conservationConditions = + result.product!.conservationConditionsInLanguages; + expect(conservationConditions, isNotNull); + expect(conservationConditions, isNotEmpty); + expect( + conservationConditions! + .containsKey(OpenFoodFactsLanguage.ALL_LANGUAGES), + isTrue); + expect(conservationConditions[OpenFoodFactsLanguage.ALL_LANGUAGES], + isNotEmpty); + expect( + conservationConditions[OpenFoodFactsLanguage.ALL_LANGUAGES], + isA() + .having((s) => s.trim().isNotEmpty, 'non-empty string', isTrue), + ); + + final customerService = result.product!.customerServiceInLanguages; + expect(customerService, isNotNull); + expect(customerService, isNotEmpty); + expect(customerService!.containsKey(OpenFoodFactsLanguage.ALL_LANGUAGES), + isTrue); + expect(customerService[OpenFoodFactsLanguage.ALL_LANGUAGES], isNotEmpty); + expect( + customerService[OpenFoodFactsLanguage.ALL_LANGUAGES], + isA() + .having((s) => s.trim().isNotEmpty, 'non-empty string', isTrue), + ); }); test('get uncommon nutrients', () async { // PROD data as of 2021-07-16 From fbd2f7cdc482d8cc5d89c6787db2be156bed45be Mon Sep 17 00:00:00 2001 From: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com> Date: Fri, 24 Jan 2025 17:56:29 +0000 Subject: [PATCH 08/10] updated the testCase and formatted using the dart format --- test/api_get_product_test.dart | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/test/api_get_product_test.dart b/test/api_get_product_test.dart index 5991c9f9ba..ad2d864bc6 100644 --- a/test/api_get_product_test.dart +++ b/test/api_get_product_test.dart @@ -235,48 +235,30 @@ void main() { test('get localized conservation conditions and customer service', () async { + const String barcode = '3017620425035'; ProductQueryConfiguration configuration = ProductQueryConfiguration( - '3017620425035', + barcode, fields: [ ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES, - ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES, + ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES ], version: ProductQueryVersion.v3, - language: OpenFoodFactsLanguage.ALL_LANGUAGES, + language: OpenFoodFactsLanguage.JAPANESE, ); ProductResultV3 result = await getProductV3InProd(configuration); expect(result.status, ProductResultV3.statusSuccess); - expect(result.product, isNotNull); + expect(result.product != null, true); final conservationConditions = result.product!.conservationConditionsInLanguages; expect(conservationConditions, isNotNull); expect(conservationConditions, isNotEmpty); - expect( - conservationConditions! - .containsKey(OpenFoodFactsLanguage.ALL_LANGUAGES), - isTrue); - expect(conservationConditions[OpenFoodFactsLanguage.ALL_LANGUAGES], - isNotEmpty); - expect( - conservationConditions[OpenFoodFactsLanguage.ALL_LANGUAGES], - isA() - .having((s) => s.trim().isNotEmpty, 'non-empty string', isTrue), - ); final customerService = result.product!.customerServiceInLanguages; expect(customerService, isNotNull); expect(customerService, isNotEmpty); - expect(customerService!.containsKey(OpenFoodFactsLanguage.ALL_LANGUAGES), - isTrue); - expect(customerService[OpenFoodFactsLanguage.ALL_LANGUAGES], isNotEmpty); - expect( - customerService[OpenFoodFactsLanguage.ALL_LANGUAGES], - isA() - .having((s) => s.trim().isNotEmpty, 'non-empty string', isTrue), - ); }); test('get uncommon nutrients', () async { // PROD data as of 2021-07-16 From e9265d945927242d28b19f1880216ee8b70855b0 Mon Sep 17 00:00:00 2001 From: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com> Date: Sat, 25 Jan 2025 17:55:55 +0000 Subject: [PATCH 09/10] Fix: Handle new fields in setLanguageString and add multilingual label tests - Updated setLanguageString in product.dart to include new fields. - Added tests to verify availability of non-primary language labels. --- lib/src/model/product.dart | 8 ++++++++ test/api_get_product_test.dart | 2 ++ 2 files changed, 10 insertions(+) diff --git a/lib/src/model/product.dart b/lib/src/model/product.dart index e0f2340937..ad591c68a8 100644 --- a/lib/src/model/product.dart +++ b/lib/src/model/product.dart @@ -773,6 +773,14 @@ class Product extends JsonObject { result.countriesTagsInLanguages ??= {}; result.countriesTagsInLanguages![language] = labels; break; + case ProductField.CONSERVATION_CONDITIONS_ALL_LANGUAGES: + result.conservationConditionsInLanguages ??= {}; + result.conservationConditionsInLanguages![language] = label; + break; + case ProductField.CUSTOMER_SERVICE_ALL_LANGUAGES: + result.customerServiceInLanguages ??= {}; + result.customerServiceInLanguages![language] = label; + break; default: // not supposed to be called with other ProductField values. assert(false); diff --git a/test/api_get_product_test.dart b/test/api_get_product_test.dart index ad2d864bc6..b2dabdb2a1 100644 --- a/test/api_get_product_test.dart +++ b/test/api_get_product_test.dart @@ -250,6 +250,8 @@ void main() { expect(result.status, ProductResultV3.statusSuccess); expect(result.product != null, true); + expect(result.product!.conservationConditionsInLanguages!.containsKey(OpenFoodFactsLanguage.FRENCH), isTrue); + expect(result.product!.customerServiceInLanguages!.containsKey(OpenFoodFactsLanguage.FRENCH), isTrue); final conservationConditions = result.product!.conservationConditionsInLanguages; From f34cd9e8a1219dd50bc5dc6301ff797ca1232e7a Mon Sep 17 00:00:00 2001 From: Affan Shaikhsurab <51104750+AffanShaikhsurab@users.noreply.github.com> Date: Sat, 25 Jan 2025 18:02:12 +0000 Subject: [PATCH 10/10] formatted using the dart format .` --- test/api_get_product_test.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/api_get_product_test.dart b/test/api_get_product_test.dart index b2dabdb2a1..055ac206fb 100644 --- a/test/api_get_product_test.dart +++ b/test/api_get_product_test.dart @@ -250,8 +250,14 @@ void main() { expect(result.status, ProductResultV3.statusSuccess); expect(result.product != null, true); - expect(result.product!.conservationConditionsInLanguages!.containsKey(OpenFoodFactsLanguage.FRENCH), isTrue); - expect(result.product!.customerServiceInLanguages!.containsKey(OpenFoodFactsLanguage.FRENCH), isTrue); + expect( + result.product!.conservationConditionsInLanguages! + .containsKey(OpenFoodFactsLanguage.FRENCH), + isTrue); + expect( + result.product!.customerServiceInLanguages! + .containsKey(OpenFoodFactsLanguage.FRENCH), + isTrue); final conservationConditions = result.product!.conservationConditionsInLanguages;