forked from openfoodfacts/openfoodfacts-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 1011 - new "getPriceProducts" method (openfoodfacts#1012)
New files: * `get_price_products_order.dart`: Field for the "order by" clause of "get price products". * `get_price_products_parameters.dart`: Parameters for the "get price products" API query. * `get_price_products_result.dart`: List of price product objects returned by the "get price products" method. * `get_price_products_result.g.dart`: generated Impacted files: * `api_prices_test.dart`: new tests around new `getPriceProducts` method; minor refactoring * `get_parameters_helper.dart`: minor refactoring * `open_prices_api_client.dart`: new `getPriceProducts` method * `openfoodfacts.dart`: exported the new 3 files
- Loading branch information
1 parent
8dc052d
commit c583648
Showing
8 changed files
with
278 additions
and
14 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
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,13 @@ | ||
import 'order_by.dart'; | ||
|
||
/// Field for the "order by" clause of "get price products". | ||
enum GetPriceProductsOrderField implements OrderByField { | ||
priceCount(offTag: 'price_count'), | ||
created(offTag: 'created'), | ||
updated(offTag: 'updated'); | ||
|
||
const GetPriceProductsOrderField({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,37 @@ | ||
import 'package:openfoodfacts/src/prices/flavor.dart'; | ||
|
||
import 'get_price_count_parameters_helper.dart'; | ||
import 'get_price_products_order.dart'; | ||
|
||
/// Parameters for the "get price products" API query. | ||
class GetPriceProductsParameters | ||
extends GetPriceCountParametersHelper<GetPriceProductsOrderField> { | ||
String? brandsLike; | ||
String? brandsTagsContains; | ||
String? categoriesTagsContains; | ||
String? code; | ||
String? ecoscoreGrade; | ||
String? labelsTagsContains; | ||
String? novaGroup; | ||
String? nutriscoreGrade; | ||
String? productNameLike; | ||
int? uniqueScansNGte; | ||
Flavor? source; | ||
|
||
@override | ||
Map<String, String> getQueryParameters() { | ||
super.getQueryParameters(); | ||
addNonNullString(brandsLike, 'brands__like'); | ||
addNonNullString(brandsTagsContains, 'brands_tags__contains'); | ||
addNonNullString(categoriesTagsContains, 'categories_tags__contains'); | ||
addNonNullString(code, 'code'); | ||
addNonNullString(ecoscoreGrade, 'ecoscore_grade'); | ||
addNonNullString(labelsTagsContains, 'labels_tags__contains'); | ||
addNonNullString(novaGroup, 'nova_group'); | ||
addNonNullString(nutriscoreGrade, 'nutriscore_grade'); | ||
addNonNullString(productNameLike, 'product_name__like'); | ||
addNonNullInt(uniqueScansNGte, 'unique_scans_n__gte'); | ||
addNonNullString(source?.offTag, 'source'); | ||
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_price_products_result.g.dart'; | ||
|
||
/// List of price product objects returned by the "get price products" method. | ||
@JsonSerializable() | ||
class GetPriceProductsResult extends JsonObject { | ||
@JsonKey() | ||
List<PriceProduct>? items; | ||
|
||
@JsonKey() | ||
int? total; | ||
|
||
@JsonKey(name: 'page') | ||
int? pageNumber; | ||
|
||
@JsonKey(name: 'size') | ||
int? pageSize; | ||
|
||
@JsonKey(name: 'pages') | ||
int? numberOfPages; | ||
|
||
GetPriceProductsResult(); | ||
|
||
factory GetPriceProductsResult.fromJson(Map<String, dynamic> json) => | ||
_$GetPriceProductsResultFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$GetPriceProductsResultToJson(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