Skip to content

Commit

Permalink
feat: #410 - refactored TaxonomyCountry with simplified fields (#412)
Browse files Browse the repository at this point in the history
Impacted files:
* `api_getTaxonomyCountries_test.dart`: refactored with the simplified fields
* `api_getTaxonomyCountriesServer_test.dart`: refactored with the simplified fields
* `LanguageHelper.dart`: added a language; added 3 json-decode helpers methods
* `Product.g.dart`: generated
* `TaxonomyCountry.dart`: added 2 fields; simplified constructor; simplified fields; removed useless `toJson` methods
* `TaxonomyCountry.g.dart`: generated
  • Loading branch information
monsieurtanuki authored Mar 15, 2022
1 parent 6a065fd commit dc77db3
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 88 deletions.
1 change: 1 addition & 0 deletions lib/model/Product.g.dart

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

52 changes: 24 additions & 28 deletions lib/model/TaxonomyCountry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ enum TaxonomyCountryField {
LANGUAGES,
NAME,
OFFICIAL_COUNTRY_CODE_2,
SYNONYMS,
WIKIDATA,
}

extension TaxonomyCountryFieldExtension on TaxonomyCountryField {
Expand All @@ -25,6 +27,8 @@ extension TaxonomyCountryFieldExtension on TaxonomyCountryField {
TaxonomyCountryField.LANGUAGES: 'languages',
TaxonomyCountryField.NAME: 'name',
TaxonomyCountryField.OFFICIAL_COUNTRY_CODE_2: 'official_country_code_2',
TaxonomyCountryField.SYNONYMS: 'synonyms',
TaxonomyCountryField.WIKIDATA: 'wikidata',
};

/// Returns the key of the Country field
Expand All @@ -37,15 +41,7 @@ extension TaxonomyCountryFieldExtension on TaxonomyCountryField {
/// of these.
@JsonSerializable()
class TaxonomyCountry extends JsonObject {
TaxonomyCountry(
this.children,
this.countryCode2,
this.countryCode3,
this.languages,
this.name,
this.officialCountryCode2,
this.parents,
);
TaxonomyCountry();

factory TaxonomyCountry.fromJson(Map<String, dynamic> json) {
return _$TaxonomyCountryFromJson(json);
Expand All @@ -56,45 +52,45 @@ class TaxonomyCountry extends JsonObject {
return _$TaxonomyCountryToJson(this);
}

@JsonKey(name: 'children', includeIfNull: false)
List<String>? children;
@JsonKey(
name: 'country_code_2',
fromJson: LanguageHelper.fromJsonStringMap,
toJson: LanguageHelper.toJsonStringMap,
fromJson: LanguageHelper.fromJsonStringMapIsoUnique,
includeIfNull: false,
)
Map<OpenFoodFactsLanguage, String>? countryCode2;
String? countryCode2;
@JsonKey(
name: 'country_code_3',
fromJson: LanguageHelper.fromJsonStringMap,
toJson: LanguageHelper.toJsonStringMap,
fromJson: LanguageHelper.fromJsonStringMapIsoUnique,
includeIfNull: false,
)
Map<OpenFoodFactsLanguage, String>? countryCode3;
String? countryCode3;
@JsonKey(
name: 'languages',
fromJson: LanguageHelper.fromJsonStringMap,
toJson: LanguageHelper.toJsonStringMap,
name: 'language_codes',
fromJson: LanguageHelper.fromJsonStringMapIsoList,
includeIfNull: false,
)
Map<OpenFoodFactsLanguage, String>? languages;
List<OpenFoodFactsLanguage>? languages;
@JsonKey(
name: 'name',
fromJson: LanguageHelper.fromJsonStringMap,
toJson: LanguageHelper.toJsonStringMap,
includeIfNull: false,
)
Map<OpenFoodFactsLanguage, String>? name;
@JsonKey(
fromJson: LanguageHelper.fromJsonStringMapList,
includeIfNull: false,
)
Map<OpenFoodFactsLanguage, List<String>>? synonyms;
@JsonKey(
fromJson: LanguageHelper.fromJsonStringMapIsoUnique,
includeIfNull: false,
)
String? wikidata;
@JsonKey(
name: 'official_country_code_2',
fromJson: LanguageHelper.fromJsonStringMap,
toJson: LanguageHelper.toJsonStringMap,
fromJson: LanguageHelper.fromJsonStringMapIsoUnique,
includeIfNull: false,
)
Map<OpenFoodFactsLanguage, String>? officialCountryCode2;
@JsonKey(name: 'parents', includeIfNull: false)
List<String>? parents;
String? officialCountryCode2;
@override
String toString() => toJson().toString();
}
Expand Down
234 changes: 217 additions & 17 deletions lib/model/TaxonomyCountry.g.dart

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

Loading

0 comments on commit dc77db3

Please sign in to comment.