From b30cf4d49e712109c8c5b9cbae9087c6b2408ef5 Mon Sep 17 00:00:00 2001 From: chetanr25 <1ds22ai010@dsce.edu.com> Date: Mon, 21 Apr 2025 01:01:12 +0530 Subject: [PATCH 1/3] feat: add additional parameters to PriceUser model --- lib/src/prices/price_user.dart | 33 +++++++++++++++++++++++++++++++ lib/src/prices/price_user.g.dart | 34 +++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/lib/src/prices/price_user.dart b/lib/src/prices/price_user.dart index 4249945db5..3f47098843 100644 --- a/lib/src/prices/price_user.dart +++ b/lib/src/prices/price_user.dart @@ -28,6 +28,39 @@ class PriceUser extends JsonObject { @JsonKey(name: 'proof_count') int? proofCount; + @JsonKey(name: 'price_type_product_count') + int? priceTypeProductCount; + + @JsonKey(name: 'price_type_category_count') + int? priceTypeCategoryCount; + + @JsonKey(name: 'price_kind_community_count') + int? priceKindCommunityCount; + + @JsonKey(name: 'price_kind_consumption_count') + int? priceKindConsumptionCount; + + @JsonKey(name: 'price_currency_count') + int? priceCurrencyCount; + + @JsonKey(name: 'price_in_proof_owned_count') + int? priceInProofOwnedCount; + + @JsonKey(name: 'price_in_proof_not_owned_count') + int? priceInProofNotOwnedCount; + + @JsonKey(name: 'price_not_owned_in_proof_owned_count') + int? priceNotOwnedInProofOwnedCount; + + @JsonKey(name: 'proof_kind_community_count') + int? proofKindCommunityCount; + + @JsonKey(name: 'proof_kind_consumption_count') + int? proofKindConsumptionCount; + + @JsonKey(name: 'location_type_osm_country_count') + int? locationTypeOsmCountryCount; + PriceUser(); factory PriceUser.fromJson(Map json) => diff --git a/lib/src/prices/price_user.g.dart b/lib/src/prices/price_user.g.dart index ac17dd106f..e2d3a90b48 100644 --- a/lib/src/prices/price_user.g.dart +++ b/lib/src/prices/price_user.g.dart @@ -11,7 +11,27 @@ PriceUser _$PriceUserFromJson(Map json) => PriceUser() ..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(); + ..proofCount = (json['proof_count'] as num?)?.toInt() + ..priceTypeProductCount = (json['price_type_product_count'] as num?)?.toInt() + ..priceTypeCategoryCount = + (json['price_type_category_count'] as num?)?.toInt() + ..priceKindCommunityCount = + (json['price_kind_community_count'] as num?)?.toInt() + ..priceKindConsumptionCount = + (json['price_kind_consumption_count'] as num?)?.toInt() + ..priceCurrencyCount = (json['price_currency_count'] as num?)?.toInt() + ..priceInProofOwnedCount = + (json['price_in_proof_owned_count'] as num?)?.toInt() + ..priceInProofNotOwnedCount = + (json['price_in_proof_not_owned_count'] as num?)?.toInt() + ..priceNotOwnedInProofOwnedCount = + (json['price_not_owned_in_proof_owned_count'] as num?)?.toInt() + ..proofKindCommunityCount = + (json['proof_kind_community_count'] as num?)?.toInt() + ..proofKindConsumptionCount = + (json['proof_kind_consumption_count'] as num?)?.toInt() + ..locationTypeOsmCountryCount = + (json['location_type_osm_country_count'] as num?)?.toInt(); Map _$PriceUserToJson(PriceUser instance) => { 'user_id': instance.userId, @@ -19,4 +39,16 @@ Map _$PriceUserToJson(PriceUser instance) => { 'location_count': instance.locationCount, 'product_count': instance.productCount, 'proof_count': instance.proofCount, + 'price_type_product_count': instance.priceTypeProductCount, + 'price_type_category_count': instance.priceTypeCategoryCount, + 'price_kind_community_count': instance.priceKindCommunityCount, + 'price_kind_consumption_count': instance.priceKindConsumptionCount, + 'price_currency_count': instance.priceCurrencyCount, + 'price_in_proof_owned_count': instance.priceInProofOwnedCount, + 'price_in_proof_not_owned_count': instance.priceInProofNotOwnedCount, + 'price_not_owned_in_proof_owned_count': + instance.priceNotOwnedInProofOwnedCount, + 'proof_kind_community_count': instance.proofKindCommunityCount, + 'proof_kind_consumption_count': instance.proofKindConsumptionCount, + 'location_type_osm_country_count': instance.locationTypeOsmCountryCount, }; From 00546ee63d7b7593ae397c2d868560e0203b12e3 Mon Sep 17 00:00:00 2001 From: chetanr25 <1ds22ai010@dsce.edu.com> Date: Mon, 21 Apr 2025 19:21:34 +0530 Subject: [PATCH 2/3] refactor: Replaced JsonSerializable with direct JSON handling, removed auto generated price_user.g.dart file --- lib/src/prices/price_user.dart | 83 +++++++++++--------------------- lib/src/prices/price_user.g.dart | 54 --------------------- 2 files changed, 29 insertions(+), 108 deletions(-) delete mode 100644 lib/src/prices/price_user.g.dart diff --git a/lib/src/prices/price_user.dart b/lib/src/prices/price_user.dart index 3f47098843..397feb0386 100644 --- a/lib/src/prices/price_user.dart +++ b/lib/src/prices/price_user.dart @@ -1,71 +1,46 @@ -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; - - @JsonKey(name: 'price_type_product_count') - int? priceTypeProductCount; - - @JsonKey(name: 'price_type_category_count') - int? priceTypeCategoryCount; - - @JsonKey(name: 'price_kind_community_count') - int? priceKindCommunityCount; - - @JsonKey(name: 'price_kind_consumption_count') - int? priceKindConsumptionCount; - - @JsonKey(name: 'price_currency_count') - int? priceCurrencyCount; - - @JsonKey(name: 'price_in_proof_owned_count') - int? priceInProofOwnedCount; - - @JsonKey(name: 'price_in_proof_not_owned_count') - int? priceInProofNotOwnedCount; - - @JsonKey(name: 'price_not_owned_in_proof_owned_count') - int? priceNotOwnedInProofOwnedCount; - - @JsonKey(name: 'proof_kind_community_count') - int? proofKindCommunityCount; - - @JsonKey(name: 'proof_kind_consumption_count') - int? proofKindConsumptionCount; - - @JsonKey(name: 'location_type_osm_country_count') - int? locationTypeOsmCountryCount; - - PriceUser(); - - factory PriceUser.fromJson(Map json) => - _$PriceUserFromJson(json); + int? get proofCount => getInt('proof_count'); + + int? get priceTypeProductCount => getInt('price_type_product_count'); + int? get priceTypeCategoryCount => getInt('price_type_category_count'); + int? get priceKindCommunityCount => getInt('price_kind_community_count'); + int? get priceKindConsumptionCount => getInt('price_kind_consumption_count'); + int? get priceCurrencyCount => getInt('price_currency_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 proofKindCommunityCount => getInt('proof_kind_community_count'); + int? get proofKindConsumptionCount => getInt('proof_kind_consumption_count'); + int? get locationTypeOsmCountryCount => + getInt('location_type_osm_country_count'); + + 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 e2d3a90b48..0000000000 --- a/lib/src/prices/price_user.g.dart +++ /dev/null @@ -1,54 +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() - ..priceTypeProductCount = (json['price_type_product_count'] as num?)?.toInt() - ..priceTypeCategoryCount = - (json['price_type_category_count'] as num?)?.toInt() - ..priceKindCommunityCount = - (json['price_kind_community_count'] as num?)?.toInt() - ..priceKindConsumptionCount = - (json['price_kind_consumption_count'] as num?)?.toInt() - ..priceCurrencyCount = (json['price_currency_count'] as num?)?.toInt() - ..priceInProofOwnedCount = - (json['price_in_proof_owned_count'] as num?)?.toInt() - ..priceInProofNotOwnedCount = - (json['price_in_proof_not_owned_count'] as num?)?.toInt() - ..priceNotOwnedInProofOwnedCount = - (json['price_not_owned_in_proof_owned_count'] as num?)?.toInt() - ..proofKindCommunityCount = - (json['proof_kind_community_count'] as num?)?.toInt() - ..proofKindConsumptionCount = - (json['proof_kind_consumption_count'] as num?)?.toInt() - ..locationTypeOsmCountryCount = - (json['location_type_osm_country_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, - 'price_type_product_count': instance.priceTypeProductCount, - 'price_type_category_count': instance.priceTypeCategoryCount, - 'price_kind_community_count': instance.priceKindCommunityCount, - 'price_kind_consumption_count': instance.priceKindConsumptionCount, - 'price_currency_count': instance.priceCurrencyCount, - 'price_in_proof_owned_count': instance.priceInProofOwnedCount, - 'price_in_proof_not_owned_count': instance.priceInProofNotOwnedCount, - 'price_not_owned_in_proof_owned_count': - instance.priceNotOwnedInProofOwnedCount, - 'proof_kind_community_count': instance.proofKindCommunityCount, - 'proof_kind_consumption_count': instance.proofKindConsumptionCount, - 'location_type_osm_country_count': instance.locationTypeOsmCountryCount, - }; From 5bae4ab3a25a4a44d4133443c77bbdf5cba55155 Mon Sep 17 00:00:00 2001 From: chetanr25 <1ds22ai010@dsce.edu.com> Date: Tue, 22 Apr 2025 00:23:11 +0530 Subject: [PATCH 3/3] added documentation for few values --- lib/src/prices/price_user.dart | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/src/prices/price_user.dart b/lib/src/prices/price_user.dart index 397feb0386..5513ff753a 100644 --- a/lib/src/prices/price_user.dart +++ b/lib/src/prices/price_user.dart @@ -24,18 +24,24 @@ class PriceUser extends JsonObject { /// Number of proofs for this user. int? get proofCount => getInt('proof_count'); - int? get priceTypeProductCount => getInt('price_type_product_count'); - int? get priceTypeCategoryCount => getInt('price_type_category_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'); - int? get priceCurrencyCount => getInt('price_currency_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'); + + 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 proofKindCommunityCount => getInt('proof_kind_community_count'); - int? get proofKindConsumptionCount => getInt('proof_kind_consumption_count'); int? get locationTypeOsmCountryCount => getInt('location_type_osm_country_count');