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

feat: #158 - introduction to folksonomy #332

Merged
merged 4 commits into from Dec 20, 2021

Conversation

monsieurtanuki
Copy link
Contributor

New files:

  • api_folksonomy_test.dart: Tests around folksonomy
  • folksonomy.dart: Client calls of the Folksonomy API (Open Food Facts)
  • KeyStats.dart: Folksonomy: statistics around a tag key.
  • ProductList.dart: Folksonomy: current value for a product and a tag key.
  • ProductStats.dart: Folksonomy: statistics about the tag keys on a product.
  • ProductTag.dart: Folksonomy product tag: for this barcode, that value is set for that key.

Impacted files:

  • HttpHelper.dart: added "delete" and "put" requests
  • JsonHelper.dart: added a helper method around timestamps
  • OpenFoodAPIConfiguration.dart: added reference URIs for folksonomy
  • openfoodfacts.dart: exported folksonomy files
  • UriHelper.dart: added a helper method for folksonomy URIs

New files:
* `api_folksonomy_test.dart`: Tests around folksonomy
* `folksonomy.dart`: Client calls of the Folksonomy API (Open Food Facts)
* `KeyStats.dart`: Folksonomy: statistics around a tag key.
* `ProductList.dart`: Folksonomy: current value for a product and a tag key.
* `ProductStats.dart`: Folksonomy: statistics about the tag keys on a product.
* `ProductTag.dart`: Folksonomy product tag: for this barcode, that value is set for that key.

Impacted files:
* `HttpHelper.dart`: added "delete" and "put" requests
* `JsonHelper.dart`: added a helper method around timestamps
* `OpenFoodAPIConfiguration.dart`: added reference URIs for folksonomy
* `openfoodfacts.dart`: exported folksonomy files
* `UriHelper.dart`: added a helper method for folksonomy URIs
Impacted files:
* `api_folksonomy_test.dart`: removed unnecessary imports
* `HttpHelper.dart`: rolled back "delete" and "put" requests
Impacted files:
* `api_saveProduct_test.dart`: unrelated test fine-tuning
Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @monsieurtanuki, the code looks really good. I have left a few comments but feel free to ignore them as they are almost all about comments.

FolksonomyAPIClient._();

/// "hello world"
static Future<void> hello({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a void doesn't make sense, lets return the answer instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for ping, returning a void does make sense. At least for me, and that's an interesting point.

If you compare to the current code in openfoodfacts, for instance https://github.com/openfoodfacts/openfoodfacts-dart/blob/master/lib/openfoodfacts.dart#L886-L890, we see that @jasmeet0817 has a problem with throwing an Exception. Should the methods handle the exception and return a clean useless value (and a step further: call Sentry) or let the developer handle the exception?

I think we should let the exceptions being thrown. We should tell the developers that our methods throw exceptions (e.g. when there's no internet, or when the server is down), and let them handle the exceptions their own way, for instance with Sentry in smoothie.

In the specific case of hello or ping, we don't give a damn about a value: we just want to know if everything was alright.

_checkResponse(response);
}

/// Returns all the [ProductStats] with that tag key, or with tag key == value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does or with tag key == value mean

lib/folksonomy.dart Show resolved Hide resolved
lib/folksonomy.dart Outdated Show resolved Hide resolved
lib/folksonomy.dart Show resolved Hide resolved
final Map<String, ProductTag> result = <String, ProductTag>{};
if (response.body == 'null') {
// not found
return result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, null or a mention in the comment

Comment on lines 325 to 326

static Future<Map<String, KeyStats>> getKeys({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comment here.

From the docs:

Get the list of keys with statistics

The keys list can be restricted to private tags from some owner

return result;
}

static Future<void> ping({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about static Future<bool> instead

Impacted files:
* `api_folksonomy_test.dart`: refactored and added tests
* `folksonomy.dart`: fixed side-effects; refactored the comments
@monsieurtanuki
Copy link
Contributor Author

Thank you @M123-dev for your code review!
I tried to be more explicit in the comments, and I added a couple of tests.
Still don't know if that makes sense to embed folksonomy here, but we can think about it until we publish the package.

@monsieurtanuki monsieurtanuki merged commit f7b254e into openfoodfacts:master Dec 20, 2021
@M123-dev
Copy link
Member

M123-dev commented Dec 20, 2021

@monsieurtanuki, lets do a new release when #336 is merged, mainly because I need the new globalUser so that I can finally PR openfoodfacts/smooth-app#700 but we can either remove the folksonomy from the CHANGELOG (and introduce it when its finsihed) or add to it, that its in work and may change.

@monsieurtanuki
Copy link
Contributor Author

@M123-dev Do what is convenient for you. folksonomy is not a top priority, smoothie is.
Beyond that, I'm not a git expert and I don't know how you can remove folksonomy from the release or the CHANGELOG, and how safe this operation would be. I'm glad there are bold people like you to do this :)

@monsieurtanuki monsieurtanuki linked an issue Dec 20, 2021 that may be closed by this pull request
@M123-dev
Copy link
Member

@monsieurtanuki

Charles answered:

There is no test server for the moment. Meanwhile there is a complete doc how to install a test version of the API: https://github.com/openfoodfacts/folksonomy_api/blob/main/INSTALL.md

I think I will install a test server, but at the beginning of 2022. If it's very important I can try to install it before, tell me.

@monsieurtanuki
Copy link
Contributor Author

Thank you @M123-dev and Charles!
Actually I don't need a test server, I only need a test user for integration tests. That could be on PROD env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add initial support for the Folksonomy Engine API
3 participants