Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a parameter serving_quantity with no corresponding ProductField #326

Open
wu-lee opened this issue Dec 16, 2021 · 7 comments · Fixed by #331
Open

There is a parameter serving_quantity with no corresponding ProductField #326

wu-lee opened this issue Dec 16, 2021 · 7 comments · Fixed by #331
Labels
🐛 bug Something isn't working

Comments

@wu-lee
Copy link

wu-lee commented Dec 16, 2021

Is your feature request related to a problem? Please describe.

I want to access the serving_quantity parameter, which I believe is a numeric value in grams. It is to serving_size (a String) what product_quantity is to quantity: a parsed and normalised numeric version of the string.

However, I can't without being able to request it via an appropriate ProductField set in the query, and there isn't one (I checked the source code too).

There also seems to be no way to select only products which have this value set, as there is for product_quantity.

Describe the solution you'd like

Please add this field so this value can be retrieved. Please also add a states tag which allows me to set a TagFilter to select only products which have this value defined.

Describe alternatives you've considered

I suppose I could abandon the Dart library and roll my own HTTP based client? But that seems counter-productive, I'm sure OFF would prefer me to use this library.

Possibly I could try and parse and normalise the string serving_size myself, but this seems hazardous, and not in keeping with the intent of this library.

Additional context

I am using the library version 1.3.8 on Android. I've checked the source of 1.7.0 and these features appear to be missing there too.

@wu-lee
Copy link
Author

wu-lee commented Dec 17, 2021

Just to add that I've tried setting ProductField.SERVING_SIZE - this results in Product.servingSize being set, but not Product.servingQuantity.

As an alternative to a new ProductField.SERVING_QUANTITY field as suggested above, possibly it could be that ProductField.SERVING_SIZE in the request indicates that both the servingSize and servingQuantity values should be supplied?

@wu-lee
Copy link
Author

wu-lee commented Dec 17, 2021

A hacky workaround I'm employing, a delegate class, which at least demonstrates that the API supports the serving_quantity field, independently of serving_size:

/// This is a hack to work around lack of a [ProductField] value for `serving_quantity`
///
/// See https://github.com/openfoodfacts/openfoodfacts-dart/issues/326
class WorkaroundProductSearchQueryConfiguration implements ProductSearchQueryConfiguration {
  final ProductSearchQueryConfiguration delegate;

  WorkaroundProductSearchQueryConfiguration(this.delegate);


  Map<String, String> getParametersMap() {
    final params = delegate.getParametersMap();
    params["fields"] = params["fields"]! + ",serving_quantity";
    print(">>> $params");
    return params;
  }

  @override
  List<Parameter> get additionalParameters => delegate.additionalParameters;
  set additionalParameters(List<Parameter> val) {
    delegate.additionalParameters = val;
  }

  @override
  String? get cc => delegate.cc;
  set cc(String? val) {
    delegate.cc = val;
  }

  @override
  List<ProductField>? get fields => delegate.fields;
  set fields(List<ProductField>? val) {
    delegate.fields = val;
  }

  @override
  OpenFoodFactsLanguage? get language => delegate.language;
  set language(OpenFoodFactsLanguage? val) {
    delegate.language = val;
  }

  @override
  List<OpenFoodFactsLanguage>? get languages => delegate.languages;
  set languages(List<OpenFoodFactsLanguage>? val) {
    delegate.languages = val;
  }

  @override
  String? get lc => delegate.lc;
  set lc(String? val) {
    delegate.lc = val;
  }

  @override
  List<String> getFieldsKeys() => delegate.getFieldsKeys();
}

@M123-dev M123-dev self-assigned this Dec 17, 2021
@M123-dev
Copy link
Member

I am going to take a look at this

@M123-dev
Copy link
Member

It's indeed missing, opening a PR in a sec

@M123-dev
Copy link
Member

@wu-lee, I added the serving_quantity in #331 to the ProductField enum. What do you mean by

Please also add a states tag which allows me to set a TagFilter to select only products which have this value defined.

Is this also solved by #331 or not

@monsieurtanuki
Copy link
Contributor

Please also add a states tag which allows me to set a TagFilter to select only products which have this value defined.

@wu-lee Correct me if I'm wrong: you expect something like "en:serving-to-be-completed" in "states_tags" to appear in the product json (e.g. in https://world.openfoodfacts.net/api/v0/product/0028400047685.json?lc=en). A bit like en:quantity-completed?
If so I guess it's first something missing on the server side. Once it's done on the server side, we'll be able to integrate that in dart.

monsieurtanuki added a commit to monsieurtanuki/openfoodfacts-dart that referenced this issue Dec 20, 2021
@wu-lee
Copy link
Author

wu-lee commented Dec 20, 2021

@wu-lee Correct me if I'm wrong: you expect something like "en:serving-to-be-completed" in "states_tags" to appear in the product json (e.g. in https://world.openfoodfacts.net/api/v0/product/0028400047685.json?lc=en). A bit like en:quantity-completed? If so I guess it's first something missing on the server side. Once it's done on the server side, we'll be able to integrate that in dart.

Thanks yes, exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Development

Successfully merging a pull request may close this issue.

3 participants