-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Impacted files: * `api_get_autocompleted_suggestions_test.dart`: added tests for ORIGINS autocomplete * `api_getProduct_test.dart`: minor refactoring * `openfoodfacts.dart`: minor refactoring * `TagType.dart`: added ORIGINS; refactored "à la 2.17" * `TaxonomyQueryConfiguration.dart`: minor refactoring
- Loading branch information
1 parent
89c5b79
commit f39e398
Showing
5 changed files
with
107 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
enum TagType { | ||
STATES, | ||
LANGUAGES, | ||
LABELS, | ||
CATEGORIES, | ||
COUNTRIES, | ||
INGREDIENTS, | ||
TRACES, | ||
ADDITIVES, | ||
ALLERGENS, | ||
PACKAGING, | ||
EMB_CODES | ||
} | ||
import 'package:openfoodfacts/model/OffTagged.dart'; | ||
|
||
enum TagType implements OffTagged { | ||
STATES(offTag: 'states'), | ||
LANGUAGES(offTag: 'languages'), | ||
LABELS(offTag: 'labels'), | ||
CATEGORIES(offTag: 'categories'), | ||
COUNTRIES(offTag: 'countries'), | ||
INGREDIENTS(offTag: 'ingredients'), | ||
TRACES(offTag: 'traces'), | ||
ADDITIVES(offTag: 'additives'), | ||
ALLERGENS(offTag: 'allergens'), | ||
PACKAGING(offTag: 'packaging'), | ||
ORIGINS(offTag: 'origins'), | ||
EMB_CODES(offTag: 'emb_codes'); | ||
|
||
const TagType({ | ||
required this.offTag, | ||
}); | ||
|
||
@override | ||
final String offTag; | ||
|
||
/// Returns the first [TagType] that matches the [offTag]. | ||
static TagType? fromOffTag(final String? offTag) => | ||
OffTagged.fromOffTag(offTag, TagType.values) as TagType?; | ||
|
||
extension TaxonomyTypeExtension on TagType { | ||
static const Map<TagType, String> _TAXONOMIES = { | ||
TagType.STATES: 'states', | ||
TagType.LABELS: 'labels', | ||
TagType.CATEGORIES: 'categories', | ||
TagType.COUNTRIES: 'countries', | ||
TagType.INGREDIENTS: 'ingredients', | ||
TagType.TRACES: 'traces', | ||
TagType.ADDITIVES: 'additives', | ||
TagType.ALLERGENS: 'allergens', | ||
TagType.PACKAGING: 'packaging', | ||
TagType.LANGUAGES: 'languages', | ||
TagType.EMB_CODES: 'emb_codes', | ||
}; | ||
String get key => _TAXONOMIES[this] ?? ''; | ||
// TODO: deprecated from 2022-10-23; remove when old enough | ||
@Deprecated('Use offTag instead') | ||
String get key => offTag; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters