diff --git a/lib/src/prices/price_user.dart b/lib/src/prices/price_user.dart index 4249945db5..5513ff753a 100644 --- a/lib/src/prices/price_user.dart +++ b/lib/src/prices/price_user.dart @@ -1,38 +1,52 @@ -import 'package:json_annotation/json_annotation.dart'; - import '../interface/json_object.dart'; -part 'price_user.g.dart'; - /// Price user object. /// /// cf. `User` in https://prices.openfoodfacts.org/api/docs -@JsonSerializable() class PriceUser extends JsonObject { - @JsonKey(name: 'user_id') - late String userId; + final Map json; + + PriceUser(this.json); + + factory PriceUser.fromJson(Map json) => PriceUser(json); + + String get userId => json['user_id'] as String; /// Number of prices for this user. - @JsonKey(name: 'price_count') - int? priceCount; + int? get priceCount => getInt('price_count'); /// Number of locations for this user. - @JsonKey(name: 'location_count') - int? locationCount; + int? get locationCount => getInt('location_count'); /// Number of products for this user. - @JsonKey(name: 'product_count') - int? productCount; + int? get productCount => getInt('product_count'); /// Number of proofs for this user. - @JsonKey(name: 'proof_count') - int? proofCount; + int? get proofCount => getInt('proof_count'); + + /// Number of unique currencies in the user's price contributions + int? get priceCurrencyCount => getInt('price_currency_count'); + + /// Number of price contributions based on category (Community or Consumption) + int? get priceKindCommunityCount => getInt('price_kind_community_count'); + int? get priceKindConsumptionCount => getInt('price_kind_consumption_count'); + + /// Number of proof contributions based on category (Community or Consumption) + int? get proofKindCommunityCount => getInt('proof_kind_community_count'); + int? get proofKindConsumptionCount => getInt('proof_kind_consumption_count'); - PriceUser(); + int? get priceTypeProductCount => getInt('price_type_product_count'); + int? get priceTypeCategoryCount => getInt('price_type_category_count'); + int? get priceInProofOwnedCount => getInt('price_in_proof_owned_count'); + int? get priceInProofNotOwnedCount => + getInt('price_in_proof_not_owned_count'); + int? get priceNotOwnedInProofOwnedCount => + getInt('price_not_owned_in_proof_owned_count'); + int? get locationTypeOsmCountryCount => + getInt('location_type_osm_country_count'); - factory PriceUser.fromJson(Map json) => - _$PriceUserFromJson(json); + int? getInt(String key) => json.containsKey(key) ? json[key] as int? : null; @override - Map toJson() => _$PriceUserToJson(this); + Map toJson() => json; } diff --git a/lib/src/prices/price_user.g.dart b/lib/src/prices/price_user.g.dart deleted file mode 100644 index ac17dd106f..0000000000 --- a/lib/src/prices/price_user.g.dart +++ /dev/null @@ -1,22 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'price_user.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -PriceUser _$PriceUserFromJson(Map json) => PriceUser() - ..userId = json['user_id'] as String - ..priceCount = (json['price_count'] as num?)?.toInt() - ..locationCount = (json['location_count'] as num?)?.toInt() - ..productCount = (json['product_count'] as num?)?.toInt() - ..proofCount = (json['proof_count'] as num?)?.toInt(); - -Map _$PriceUserToJson(PriceUser instance) => { - 'user_id': instance.userId, - 'price_count': instance.priceCount, - 'location_count': instance.locationCount, - 'product_count': instance.productCount, - 'proof_count': instance.proofCount, - };