Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions lib/src/prices/price_user.dart
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> json;

PriceUser(this.json);

factory PriceUser.fromJson(Map<String, dynamic> 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<String, dynamic> json) =>
_$PriceUserFromJson(json);
int? getInt(String key) => json.containsKey(key) ? json[key] as int? : null;

@override
Map<String, dynamic> toJson() => _$PriceUserToJson(this);
Map<String, dynamic> toJson() => json;
}
22 changes: 0 additions & 22 deletions lib/src/prices/price_user.g.dart

This file was deleted.

Loading