Skip to content

Commit

Permalink
refactor: used OffTagged and removed deprecated fields (#607)
Browse files Browse the repository at this point in the history
Impacted files:
* `AbstractQueryConfiguration.dart`: removed deprecated field `cc`
* `OpenFoodAPIConfiguration.dart`: removed deprecated field `globalCc`
* `ProductListQueryConfiguration.dart`: removed deprecated field `cc`
* `ProductQueryConfigurations.dart`: removed deprecated field `cc`
* `ProductSearchQueryConfiguration.dart`: removed deprecated field `cc`
* `TagFilter.dart`: refactored with `OffTagged`; removed deprecated constructor
* `TaxonomyAdditive.dart`: removed deprecated field `cc`
* `TaxonomyAllergen.dart`: removed deprecated field `cc`
* `TaxonomyCategory.dart`: removed deprecated field `cc`
* `TaxonomyCountry.dart`: removed deprecated field `cc`; refactored with `OffTagged`
* `TaxonomyIngredient.dart`: removed deprecated field `cc`
* `TaxonomyLabel.dart`: removed deprecated field `cc`
* `TaxonomyLanguage.dart`: removed deprecated field `cc`
* `TaxonomyQueryConfiguration.dart`: removed deprecated field `cc`
  • Loading branch information
monsieurtanuki committed Nov 6, 2022
1 parent f6fd904 commit 39e17a6
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 141 deletions.
2 changes: 0 additions & 2 deletions lib/model/TaxonomyAdditive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,13 @@ class TaxonomyAdditiveQueryConfiguration extends TaxonomyQueryConfiguration<
TaxonomyAdditiveQueryConfiguration({
required List<String> tags,
List<OpenFoodFactsLanguage>? languages,
@Deprecated('Use parameter country instead') String? cc,
OpenFoodFactsCountry? country,
List<TaxonomyAdditiveField> fields = const [],
List<Parameter> additionalParameters = const [],
}) : super(
TagType.ADDITIVES,
tags,
languages: languages,
cc: cc,
country: country,
includeChildren: false,
fields: fields,
Expand Down
2 changes: 0 additions & 2 deletions lib/model/TaxonomyAllergen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ class TaxonomyAllergenQueryConfiguration extends TaxonomyQueryConfiguration<
TaxonomyAllergenQueryConfiguration({
required List<String> tags,
List<OpenFoodFactsLanguage>? languages,
@Deprecated('Use parameter country instead') String? cc,
OpenFoodFactsCountry? country,
List<TaxonomyAllergenField> fields = const [],
List<Parameter> additionalParameters = const [],
}) : super(
TagType.ALLERGENS,
tags,
languages: languages,
cc: cc,
country: country,
fields: fields,
additionalParameters: additionalParameters,
Expand Down
4 changes: 0 additions & 4 deletions lib/model/TaxonomyCategory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ class TaxonomyCategoryQueryConfiguration extends TaxonomyQueryConfiguration<
TaxonomyCategoryQueryConfiguration({
required List<String> tags,
List<OpenFoodFactsLanguage>? languages,
@Deprecated('Use parameter country instead') String? cc,
OpenFoodFactsCountry? country,
bool includeChildren = false,
List<TaxonomyCategoryField> fields = const [],
Expand All @@ -344,7 +343,6 @@ class TaxonomyCategoryQueryConfiguration extends TaxonomyQueryConfiguration<
TagType.CATEGORIES,
tags,
languages: languages,
cc: cc,
country: country,
includeChildren: includeChildren,
fields: fields,
Expand All @@ -353,15 +351,13 @@ class TaxonomyCategoryQueryConfiguration extends TaxonomyQueryConfiguration<

TaxonomyCategoryQueryConfiguration.roots({
List<OpenFoodFactsLanguage>? languages,
@Deprecated('Use parameter country instead') String? cc,
OpenFoodFactsCountry? country,
bool includeChildren = false,
List<TaxonomyCategoryField> fields = const [],
List<Parameter> additionalParameters = const [],
}) : super.roots(
TagType.CATEGORIES,
languages: languages,
cc: cc,
country: country,
includeChildren: includeChildren,
fields: fields,
Expand Down
44 changes: 18 additions & 26 deletions lib/model/TaxonomyCountry.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:openfoodfacts/interface/JsonObject.dart';
import 'package:openfoodfacts/model/OffTagged.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:openfoodfacts/utils/CountryHelper.dart';
import 'package:openfoodfacts/utils/TaxonomyQueryConfiguration.dart';
Expand All @@ -8,31 +9,24 @@ import 'package:openfoodfacts/utils/TagType.dart';
part 'TaxonomyCountry.g.dart';

/// Fields of an [TaxonomyCountry]
enum TaxonomyCountryField {
ALL,
COUNTRY_CODE_2,
COUNTRY_CODE_3,
LANGUAGES,
NAME,
OFFICIAL_COUNTRY_CODE_2,
SYNONYMS,
WIKIDATA,
}
enum TaxonomyCountryField implements OffTagged {
ALL(offTag: 'all'),
COUNTRY_CODE_2(offTag: 'country_code_2'),
COUNTRY_CODE_3(offTag: 'country_code_3'),
LANGUAGES(offTag: 'languages'),
NAME(offTag: 'name'),
OFFICIAL_COUNTRY_CODE_2(offTag: 'official_country_code_2'),
SYNONYMS(offTag: 'synonyms'),
WIKIDATA(offTag: 'wikidata');

const TaxonomyCountryField({required this.offTag});

extension TaxonomyCountryFieldExtension on TaxonomyCountryField {
static const Map<TaxonomyCountryField, String> _KEYS = {
TaxonomyCountryField.ALL: 'all',
TaxonomyCountryField.COUNTRY_CODE_2: 'country_code_2',
TaxonomyCountryField.COUNTRY_CODE_3: 'country_code_3',
TaxonomyCountryField.LANGUAGES: 'languages',
TaxonomyCountryField.NAME: 'name',
TaxonomyCountryField.OFFICIAL_COUNTRY_CODE_2: 'official_country_code_2',
TaxonomyCountryField.SYNONYMS: 'synonyms',
TaxonomyCountryField.WIKIDATA: 'wikidata',
};
@override
final String offTag;

/// Returns the key of the Country field
String get key => _KEYS[this] ?? '';
// TODO: deprecated from 2022-11-06; remove when old enough
@Deprecated('Use offTag instead')
String get key => offTag;
}

/// A JSON-serializable version of a Country taxonomy result.
Expand Down Expand Up @@ -102,15 +96,13 @@ class TaxonomyCountryQueryConfiguration
TaxonomyCountryQueryConfiguration({
required List<String> tags,
List<OpenFoodFactsLanguage>? languages,
@Deprecated('Use parameter country instead') String? cc,
OpenFoodFactsCountry? country,
List<TaxonomyCountryField> fields = const [],
List<Parameter> additionalParameters = const [],
}) : super(
TagType.COUNTRIES,
tags,
languages: languages,
cc: cc,
country: country,
includeChildren: false,
fields: fields,
Expand Down Expand Up @@ -155,6 +147,6 @@ class TaxonomyCountryQueryConfiguration
Iterable<TaxonomyCountryField> fields) {
return fields
.where((TaxonomyCountryField field) => !ignoredFields.contains(field))
.map<String>((TaxonomyCountryField field) => field.key);
.map<String>((TaxonomyCountryField field) => field.offTag);
}
}
4 changes: 0 additions & 4 deletions lib/model/TaxonomyIngredient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ class TaxonomyIngredientQueryConfiguration extends TaxonomyQueryConfiguration<
TaxonomyIngredientQueryConfiguration({
required List<String> tags,
List<OpenFoodFactsLanguage>? languages,
@Deprecated('Use parameter country instead') String? cc,
OpenFoodFactsCountry? country,
List<TaxonomyIngredientField> fields = const [],
List<Parameter> additionalParameters = const [],
Expand All @@ -481,7 +480,6 @@ class TaxonomyIngredientQueryConfiguration extends TaxonomyQueryConfiguration<
TagType.INGREDIENTS,
tags,
languages: languages,
cc: cc,
country: country,
includeChildren: includeChildren,
fields: fields,
Expand All @@ -490,15 +488,13 @@ class TaxonomyIngredientQueryConfiguration extends TaxonomyQueryConfiguration<

TaxonomyIngredientQueryConfiguration.roots({
List<OpenFoodFactsLanguage>? languages,
@Deprecated('Use parameter country instead') String? cc,
OpenFoodFactsCountry? country,
List<TaxonomyIngredientField> fields = const [],
List<Parameter> additionalParameters = const [],
bool includeChildren = false,
}) : super.roots(
TagType.INGREDIENTS,
languages: languages,
cc: cc,
country: country,
includeChildren: includeChildren,
fields: fields,
Expand Down
4 changes: 0 additions & 4 deletions lib/model/TaxonomyLabel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,13 @@ class TaxonomyLabelQueryConfiguration
TaxonomyLabelQueryConfiguration({
required List<String> tags,
List<OpenFoodFactsLanguage>? languages,
@Deprecated('Use parameter country instead') String? cc,
OpenFoodFactsCountry? country,
List<TaxonomyLabelField> fields = const [],
List<Parameter> additionalParameters = const [],
}) : super(
TagType.LABELS,
tags,
languages: languages,
cc: cc,
country: country,
includeChildren: false,
fields: fields,
Expand All @@ -297,14 +295,12 @@ class TaxonomyLabelQueryConfiguration

TaxonomyLabelQueryConfiguration.roots({
List<OpenFoodFactsLanguage>? languages,
@Deprecated('Use parameter country instead') String? cc,
OpenFoodFactsCountry? country,
List<TaxonomyLabelField> fields = const [],
List<Parameter> additionalParameters = const [],
}) : super.roots(
TagType.LABELS,
languages: languages,
cc: cc,
country: country,
includeChildren: false,
fields: fields,
Expand Down
2 changes: 0 additions & 2 deletions lib/model/TaxonomyLanguage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,13 @@ class TaxonomyLanguageQueryConfiguration extends TaxonomyQueryConfiguration<
TaxonomyLanguageQueryConfiguration({
required List<String> tags,
List<OpenFoodFactsLanguage>? languages,
@Deprecated('Use parameter country instead') String? cc,
OpenFoodFactsCountry? country,
List<TaxonomyLanguageField> fields = const [],
List<Parameter> additionalParameters = const [],
}) : super(
TagType.LANGUAGES,
tags,
languages: languages,
cc: cc,
country: country,
fields: fields,
additionalParameters: additionalParameters,
Expand Down
94 changes: 33 additions & 61 deletions lib/model/parameter/TagFilter.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,40 @@
import 'package:openfoodfacts/interface/Parameter.dart';
import 'package:openfoodfacts/model/OffTagged.dart';

/// Filter types for advanced search parameters
enum TagFilterType {
BRANDS,
CATEGORIES,
PACKAGING,
LABELS,
ORIGINS,
MANUFACTURING_PLACES,
EMB_CODES,
PURCHASE_PLACES,
STORES,
COUNTRIES,
ADDITIVES,
ALLERGENS,
TRACES,
NUTRITION_GRADES,
STATES,
INGREDIENTS,
NOVA_GROUPS,
LANGUAGES,
CREATOR,
EDITORS,
LANG,
}
enum TagFilterType implements OffTagged {
BRANDS(offTag: 'brands'),
CATEGORIES(offTag: 'categories'),
PACKAGING(offTag: 'packaging'),
LABELS(offTag: 'labels'),
ORIGINS(offTag: 'origins'),
MANUFACTURING_PLACES(offTag: 'manufacturing_places'),
EMB_CODES(offTag: 'emb_codes'),
PURCHASE_PLACES(offTag: 'purchase_places'),
STORES(offTag: 'stores'),
COUNTRIES(offTag: 'countries'),
ADDITIVES(offTag: 'additives'),
ALLERGENS(offTag: 'allergens'),
TRACES(offTag: 'traces'),
NUTRITION_GRADES(offTag: 'nutrition_grades'),
STATES(offTag: 'states'),
INGREDIENTS(offTag: 'ingredients'),
NOVA_GROUPS(offTag: 'nova_groups'),
LANGUAGES(offTag: 'languages'),
CREATOR(offTag: 'creator'),
EDITORS(offTag: 'editors'),
LANG(offTag: 'lang');

extension TagFilterTypeExtension on TagFilterType {
static const Map<TagFilterType, String> _map = <TagFilterType, String>{
TagFilterType.BRANDS: 'brands',
TagFilterType.CATEGORIES: 'categories',
TagFilterType.PACKAGING: 'packaging',
TagFilterType.LABELS: 'labels',
TagFilterType.ORIGINS: 'origins',
TagFilterType.MANUFACTURING_PLACES: 'manufacturing_places',
TagFilterType.EMB_CODES: 'emb_codes',
TagFilterType.PURCHASE_PLACES: 'purchase_places',
TagFilterType.STORES: 'stores',
TagFilterType.COUNTRIES: 'countries',
TagFilterType.ADDITIVES: 'additives',
TagFilterType.ALLERGENS: 'allergens',
TagFilterType.TRACES: 'traces',
TagFilterType.NUTRITION_GRADES: 'nutrition_grades',
TagFilterType.STATES: 'states',
TagFilterType.INGREDIENTS: 'ingredients',
TagFilterType.NOVA_GROUPS: 'nova_groups',
TagFilterType.LANGUAGES: 'languages',
TagFilterType.CREATOR: 'creator',
TagFilterType.EDITORS: 'editors',
TagFilterType.LANG: 'lang',
};
const TagFilterType({
required this.offTag,
});

String get key => _map[this]!;
@override
final String offTag;

// TODO: deprecated from 2022-11-06; remove when old enough
@Deprecated('Use offTag instead')
String get key => offTag;
}

/// Tag filter ("LIST contains/without ITEM") search API parameter
Expand Down Expand Up @@ -78,18 +62,6 @@ class TagFilter extends Parameter {
final bool contains;
final String tagName;

// TODO: deprecated from 2021-12-12 (#307); remove when old enough
@Deprecated('Use TagFilter.fromType instead')
const TagFilter({
required final String tagType,
required final bool contains,
required final String tagName,
}) : this._(
tagType: tagType,
contains: contains,
tagName: tagName,
);

const TagFilter._({
required this.tagType,
required this.contains,
Expand All @@ -101,7 +73,7 @@ class TagFilter extends Parameter {
required final String tagName,
final bool contains = true,
}) : this._(
tagType: tagFilterType.key,
tagType: tagFilterType.offTag,
contains: contains,
tagName: tagName,
);
Expand Down
8 changes: 1 addition & 7 deletions lib/utils/AbstractQueryConfiguration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ abstract class AbstractQueryConfiguration {
/// for detailed explanation on how to work with multiple languages.
List<OpenFoodFactsLanguage>? languages;

// TODO: deprecated from 2021-11-15 (#233); remove when old enough
@Deprecated('Use parameter country instead')
String? cc;

/// The country for this query, if any.
final OpenFoodFactsCountry? country;

Expand All @@ -46,7 +42,6 @@ abstract class AbstractQueryConfiguration {
AbstractQueryConfiguration({
this.language,
this.languages,
this.cc,
this.country,
this.fields,
this.additionalParameters = const [],
Expand Down Expand Up @@ -115,8 +110,7 @@ abstract class AbstractQueryConfiguration {
}

String? computeCountryCode() =>
// ignore: deprecated_member_use_from_same_package
OpenFoodAPIConfiguration.computeCountryCode(country, cc);
OpenFoodAPIConfiguration.computeCountryCode(country, null);

@protected
String getUriPath();
Expand Down
12 changes: 0 additions & 12 deletions lib/utils/OpenFoodAPIConfiguration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ class OpenFoodAPIConfiguration {
/// individual request configurations
static List<OpenFoodFactsLanguage>? globalLanguages;

///A global way to specify the country code for queries, can be overwritten
/// for each individual request by specifying the country code in the
/// individual request configurations
// TODO: deprecated from 2021-11-15 (#233); remove when old enough
@Deprecated('Use field globalCountry instead')
static String? globalCC;

///A global way to specify the country code for queries, can be overwritten
/// for each individual request by specifying the country code in the
/// individual request configurations
Expand All @@ -97,11 +90,6 @@ class OpenFoodAPIConfiguration {
if (cc != null) {
return cc;
}
// ignore: deprecated_member_use_from_same_package
if (OpenFoodAPIConfiguration.globalCC != null) {
// ignore: deprecated_member_use_from_same_package
return OpenFoodAPIConfiguration.globalCC;
}
return null;
}
}
Loading

0 comments on commit 39e17a6

Please sign in to comment.