-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 831 - Prices getLocation, getPriceProduct, getStatus methods (#855
) New files: * `location.dart`: Location object in the Prices API. * `location.g.dart`: generated * `price_product.dart`: Product object in the Prices API. * `price_product.g.dart`: generated Impacted files: * `api_prices_test.dart`: added tests for `getLocation`, `getPriceProduct` and `getStatus` * `open_prices_api_client.dart`: new methods `getLocation`, `getPriceProduct` and `getStatus` * `openfoodfacts.dart`: exported the 2 new files * `price.dart`: minor refactoring * `price.g.dart`: generated
- Loading branch information
1 parent
34d68bf
commit e18080b
Showing
9 changed files
with
298 additions
and
26 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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
import 'location_osm_type.dart'; | ||
import '../interface/json_object.dart'; | ||
import '../utils/json_helper.dart'; | ||
|
||
part 'location.g.dart'; | ||
|
||
/// Location object in the Prices API. | ||
/// | ||
/// cf. `LocationBase` in https://prices.openfoodfacts.net/docs | ||
@JsonSerializable() | ||
class Location extends JsonObject { | ||
/// ID of the location in OpenStreetMap: the store where the product was bought. | ||
@JsonKey(name: 'osm_id') | ||
late int osmId; | ||
|
||
/// Type of the OpenStreetMap location object. | ||
/// | ||
/// Stores can be represented as nodes, ways or relations in OpenStreetMap. | ||
/// It is necessary to be able to fetch the correct information about the | ||
/// store using the ID. | ||
@JsonKey(name: 'osm_type') | ||
late LocationOSMType type; | ||
|
||
/// ID in the Prices API. | ||
@JsonKey(name: 'id') | ||
late int locationId; | ||
|
||
@JsonKey(name: 'osm_name') | ||
String? name; | ||
|
||
@JsonKey(name: 'osm_display_name') | ||
String? displayName; | ||
|
||
@JsonKey(name: 'osm_address_postcode') | ||
String? postcode; | ||
|
||
@JsonKey(name: 'osm_address_city') | ||
String? city; | ||
|
||
@JsonKey(name: 'osm_address_country') | ||
String? country; | ||
|
||
@JsonKey(name: 'osm_lat') | ||
double? latitude; | ||
|
||
@JsonKey(name: 'osm_lon') | ||
double? longitude; | ||
|
||
/// Date when the product was bought. | ||
@JsonKey(fromJson: JsonHelper.stringTimestampToDate) | ||
late DateTime created; | ||
|
||
/// Date when the product was bought. | ||
@JsonKey(fromJson: JsonHelper.nullableStringTimestampToDate) | ||
DateTime? updated; | ||
|
||
Location(); | ||
|
||
factory Location.fromJson(Map<String, dynamic> json) => | ||
_$LocationFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$LocationToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
import '../interface/json_object.dart'; | ||
import '../utils/json_helper.dart'; | ||
|
||
part 'price_product.g.dart'; | ||
|
||
/// Product object in the Prices API. | ||
/// | ||
/// cf. `ProductBase` in https://prices.openfoodfacts.net/docs | ||
@JsonSerializable() | ||
class PriceProduct extends JsonObject { | ||
@JsonKey() | ||
late String code; | ||
|
||
@JsonKey(name: 'id') | ||
late int productId; | ||
|
||
@JsonKey() | ||
String? source; | ||
|
||
@JsonKey(name: 'product_name') | ||
String? name; | ||
|
||
@JsonKey(name: 'product_quantity') | ||
int? quantity; | ||
|
||
@JsonKey(name: 'image_url') | ||
String? imageURL; | ||
|
||
@JsonKey(fromJson: JsonHelper.stringTimestampToDate) | ||
late DateTime created; | ||
|
||
@JsonKey(fromJson: JsonHelper.nullableStringTimestampToDate) | ||
DateTime? updated; | ||
|
||
PriceProduct(); | ||
|
||
factory PriceProduct.fromJson(Map<String, dynamic> json) => | ||
_$PriceProductFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$PriceProductToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.