-
-
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 - latest "prices" API changes (#897)
Deleted files: * `get_prices_results.dart` * `validation_error.dart` * `validation_error.g.dart` * `validation_errors.dart` * `validation_errors.g.dart` New files: * `get_locations_order.dart`: Field for the "order by" clause of "get locations". * `get_locations_parameters.dart`: Parameters for the "get locations" API query. * `get_locations_result.dart`: List of location objects returned by the "get locations" method. * `get_locations_result.g.dart`: generated * `order_by.dart`: "Order by" clause for "get list" methods (e.g. "get prices") Impacted files: * `api_prices_test.dart`: impacted by `MaybeError` refactoring; tests for new methods `getOSMLocation`, `getLocations`, `getPriceProductByCode` * `get_prices_order.dart`: refactored using new class `OrderByField` * `get_prices_parameters.dart`: refactored using new class `OrderBy` * `open_prices_api_client.dart`: refactored using more systematically `MaybeError`; renamed `getPriceProduct` as `getPriceProductById`; added methods `getOSMLocation`, `getLocations`, `getPriceProductByCode` * `openfoodfacts.dart`: added the new files; removed the deleted files
- Loading branch information
1 parent
56446da
commit 88dada6
Showing
15 changed files
with
468 additions
and
168 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,12 @@ | ||
import 'order_by.dart'; | ||
|
||
/// Field for the "order by" clause of "get locations". | ||
enum GetLocationsOrderField implements OrderByField { | ||
created(offTag: 'created'), | ||
updated(offTag: 'updated'); | ||
|
||
const GetLocationsOrderField({required this.offTag}); | ||
|
||
@override | ||
final String offTag; | ||
} |
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,39 @@ | ||
import 'get_locations_order.dart'; | ||
import 'order_by.dart'; | ||
import 'get_parameters_helper.dart'; | ||
|
||
/// Parameters for the "get locations" API query. | ||
/// | ||
/// cf. https://prices.openfoodfacts.org/api/docs | ||
class GetLocationsParameters extends GetParametersHelper { | ||
String? osmNameLike; | ||
String? osmCityLike; | ||
String? osmPostcodeLike; | ||
String? osmCountryLike; | ||
int? priceCount; | ||
int? priceCountGte; | ||
int? priceCountLte; | ||
List<OrderBy<GetLocationsOrderField>>? orderBy; | ||
|
||
@override | ||
Map<String, String> getQueryParameters() { | ||
super.getQueryParameters(); | ||
addNonNullString(osmNameLike, 'osm_name__like'); | ||
addNonNullString(osmCityLike, 'osm_address_city__like'); | ||
addNonNullString(osmPostcodeLike, 'osm_address_postcode__like'); | ||
addNonNullString(osmCountryLike, 'osm_address_country__like'); | ||
addNonNullInt(priceCount, 'price_count'); | ||
addNonNullInt(priceCountGte, 'price_count__gte'); | ||
addNonNullInt(priceCountLte, 'price_count__lte'); | ||
if (orderBy != null) { | ||
final List<String> orders = <String>[]; | ||
for (final OrderBy order in orderBy!) { | ||
orders.add(order.offTag); | ||
} | ||
if (orders.isNotEmpty) { | ||
addNonNullString(orders.join(','), 'order_by'); | ||
} | ||
} | ||
return result; | ||
} | ||
} |
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,33 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
|
||
import '../interface/json_object.dart'; | ||
|
||
part 'get_locations_result.g.dart'; | ||
|
||
/// List of location objects returned by the "get locations" method. | ||
@JsonSerializable() | ||
class GetLocationsResult extends JsonObject { | ||
@JsonKey() | ||
List<Location>? items; | ||
|
||
@JsonKey() | ||
int? total; | ||
|
||
@JsonKey(name: 'page') | ||
int? pageNumber; | ||
|
||
@JsonKey(name: 'size') | ||
int? pageSize; | ||
|
||
@JsonKey(name: 'pages') | ||
int? numberOfPages; | ||
|
||
GetLocationsResult(); | ||
|
||
factory GetLocationsResult.fromJson(Map<String, dynamic> json) => | ||
_$GetLocationsResultFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$GetLocationsResultToJson(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.