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: 831 - new price methods like add price and upload proof #884

Merged
merged 4 commits into from Feb 16, 2024

Conversation

monsieurtanuki
Copy link
Contributor

What

Now we're getting serious about prices with the following new methods:

  • getAuthenticationToken to start a session with authentication
  • getUserSession to check if a session is running
  • deleteUserSession to close a session
  • createPrice to add a price
  • deletePrice to delete a price
  • uploadProof to upload a proof
  • deleteProof to delete a proof

Part of

Files

New files:

  • maybe_error.dart: Contains a successful value OR an error.
  • price_per.dart: Price Per.
  • proof.dart: Proof of a price.
  • proof.g.dart: generated
  • proof_type.dart: Type of a Proof.
  • session.dart: Price session.
  • session.g.dart: generated

Impacted files:

  • api_get_save_product_test.dart: unrelated minor fix
  • api_prices_test.dart: added tests for the new methods
  • http_helper.dart: added optional "bearerToken" parameter to GET; new doDeleteRequest, doPostJsonRequest and imagineMediaType methods
  • open_prices_api_client.dart: added parameters to getPrices; new methods getAuthenticationToken, getUserSession, deleteUserSession, createPrice, deletePrice, uploadProof and deleteProof; minor refactoring
  • openfoodfacts.dart: added 5 new files to export
  • price.dart: added fields.
  • price.g.dart: generated
  • pubspec.yaml: added package http_parser for MediaType
  • test_constants.dart: unrelated minor fix

New files:
* `maybe_error.dart`: Contains a successful value OR an error.
* `price_per.dart`: Price Per.
* `proof.dart`: Proof of a price.
* `proof.g.dart`: generated
* `proof_type.dart`: Type of a Proof.
* `session.dart`: Price session.
* `session.g.dart`: generated

Impacted files:
* `api_get_save_product_test.dart`: unrelated minor fix
* `api_prices_test.dart`: added tests for the new methods
* `http_helper.dart`: added optional "bearerToken" parameter to GET; new `doDeleteRequest`, `doPostJsonRequest` and `imagineMediaType` methods
* `open_prices_api_client.dart`: added parameters to `getPrices`; new methods `getAuthenticationToken`, `getUserSession`, `deleteUserSession`, `createPrice`, `deletePrice`, `uploadProof` and `deleteProof`; minor refactoring
* `openfoodfacts.dart`: added 5 new files to export
* `price.dart`: added fields.
* `price.g.dart`: generated
* `pubspec.yaml`: added package `http_parser` for `MediaType`
* `test_constants.dart`: unrelated minor fix
@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2024

Codecov Report

Attention: 47 lines in your changes are missing coverage. Please review.

Comparison is base (cdc4899) 75.64% compared to head (69b4920) 76.01%.

Files Patch % Lines
lib/src/open_prices_api_client.dart 82.45% 20 Missing ⚠️
lib/src/prices/proof.g.dart 50.00% 9 Missing ⚠️
lib/src/prices/price.g.dart 53.33% 7 Missing ⚠️
lib/src/prices/session.g.dart 50.00% 4 Missing ⚠️
lib/src/prices/proof.dart 50.00% 2 Missing ⚠️
lib/src/prices/session.dart 60.00% 2 Missing ⚠️
lib/src/prices/maybe_error.dart 90.90% 1 Missing ⚠️
test/api_get_save_product_test.dart 0.00% 1 Missing ⚠️
test/api_prices_test.dart 99.18% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #884      +/-   ##
==========================================
+ Coverage   75.64%   76.01%   +0.36%     
==========================================
  Files         231      236       +5     
  Lines        8085     8391     +306     
==========================================
+ Hits         6116     6378     +262     
- Misses       1969     2013      +44     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 a lot @monsieurtanuki, added some minor comments 👍🏼

lib/src/open_prices_api_client.dart Show resolved Hide resolved
lib/src/open_prices_api_client.dart Show resolved Hide resolved
lib/src/open_prices_api_client.dart Outdated Show resolved Hide resolved
lib/src/open_prices_api_client.dart Outdated Show resolved Hide resolved
Comment on lines +254 to +256
if (bearerToken != null) {
return _getBearerHeader(bearerToken);
}
Copy link
Member

Choose a reason for hiding this comment

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

Don't we want a user agent and a "From" header. Just because prices does not use them yet it could be interesting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't we want a user agent and a "From" header. Just because prices does not use them yet it could be interesting

Could be done later if needed, for stats I guess.
I don't know if prices plan to do something with it.
For the moment the code is clearer to read that way: "token? just return this! else do as usual".

monsieurtanuki and others added 2 commits February 16, 2024 07:03
Co-authored-by: Marvin Möltgen <39344769+M123-dev@users.noreply.github.com>
Co-authored-by: Marvin Möltgen <39344769+M123-dev@users.noreply.github.com>
@monsieurtanuki
Copy link
Contributor Author

Thank you very much @M123-dev for your quick (but detailed) review!

Regarding verbose comments, I don't know the best practice: is it relevant to copy the API comments here, as they can be outdated? Is it relevant to just point to the API docs?

@monsieurtanuki monsieurtanuki merged commit 7615fcb into openfoodfacts:master Feb 16, 2024
3 checks passed
@raphael0202
Copy link

Great 🎉

@monsieurtanuki
Copy link
Contributor Author

@raphael0202 Today I'll PR a bigger getPrices, which will give us a feature we need in Smoothie: get the latest prices for a product (order by created desc, or created desc)

I'm still a bit stuck with the "get location" feature, that we need too:

  • is there an easy way (OSM or prices) to get the OSM shops with a query like "monoprix, avenue daumesnil, paris"?
  • is there an easy way (OSM or prices) to get the OSM shops close to a geopoint?

Perhaps we would need the prices for a product within 5km.

@raphael0202
Copy link

is there an easy way (OSM or prices) to get the OSM shops with a query like "monoprix, avenue daumesnil, paris"?

Currently we use OSM Nominatim, which does the job (but is far from perfect). Can you use it as well here?

is there an easy way (OSM or prices) to get the OSM shops close to a geopoint?

Hum I'm not sure of this, maybe @raphodn will know better

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

Successfully merging this pull request may close these issues.

None yet

5 participants