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

Improve API (API 1.1) #421

Open
wants to merge 19 commits into
base: next
Choose a base branch
from
Open

Improve API (API 1.1) #421

wants to merge 19 commits into from

Conversation

krestenlaust
Copy link
Member

@krestenlaust krestenlaust commented Apr 7, 2024

#420 aims to document the API. This PR addresses inconsistencies found during that documentation effort. Both in implementation and in the actual API.

It increments the API versioning to 1.1

The other endpoints use 'Invalid ID' to signify either missing or
invalid. This endpoint used to use 'Invalid Username' to signify that the
member does not exist, while the other's would've used 'Member not
found' for that.
krestenlaust added a commit that referenced this pull request Apr 8, 2024
There's an inconsistency in whether to call a member a user. Generally,
users are the ones with admin access, while members are the customers.
Even though it's a bool, I believe it's more appropriate to keep the
naming consistent with non-bool return types. Also, it still returns an
object.
I won't rename the actual endpoint because of backwards compatibility.
@krestenlaust
Copy link
Member Author

QR-endpoint apparently uses Stregdollars as opposed to Stregøre. I feel like streamlining this is too big a change.
The QR-endpoint also takes a member parameter, which will probably be renamed to username to streamline with other Member API-methods. (member will probably still be supported)

@krestenlaust
Copy link
Member Author


Changed response text on error to this format

More meaningful response in Active Products-endpoint, now returns {"1":
{"name": "Beer", "price": 600}}, instead of {"1": ["Beer", 600]}
@krestenlaust
Copy link
Member Author

Changed response format for Active Products-endpoint:
{"1": {"name": "Test ØL", "price": 100}, "2": {"name": "Kold Kaffe", "price": 200}, "3": {"name": "Fadøl", "price": 1500}, "13": {"name": "Fake ØL", "price": 300}, "32": {"name": "Kold Kaffe", "price": 200}, "34": {"name": "Fnugfald", "price": 0}}

Instead of {"1": ["Test ØL", 100], ...}

@krestenlaust
Copy link
Member Author

Changed format for Category_mapping endpoint output:
{"1": [], "2": [], "3": [], "13": [], "32": [[6, "kaffe"]], "33": [], "34": []} -> {"1": [], "2": [], "3": [], "13": [], "32": [{"category_id": 6, "category_name": "kaffe"}], "33": [], "34": []}

Much more verbose, but it's more like the other endpoints. Considering changing it to not return products which don't have any mapped categories

@krestenlaust
Copy link
Member Author

I've decided to leave the sales API as is

@krestenlaust krestenlaust marked this pull request as ready for review October 24, 2024 13:48
Copy link
Member

@Mast3rwaf1z Mast3rwaf1z left a comment

Choose a reason for hiding this comment

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

a few small changes, but looks nice 👍

re_path(r'^api/member/get_id$', views.get_member_id, name="get_member_id"),
re_path(r'^api/member/balance$', views.get_member_balance, name="get_member_balance"),
re_path(r'^api/member$', views.get_member_info, name="get_member_info"),
re_path(r'^api/products/named_products$', views.dump_named_products, name="dump_named_products"),
Copy link
Member

Choose a reason for hiding this comment

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

why not get_named_products and get_active_products? this change seems related to making better function names, so why not follow what is above?


data = 'mobilepay://send?{}'.format(urllib.parse.urlencode(query))
Copy link
Member

Choose a reason for hiding this comment

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

remove urllib.parse import

try:
member = Member.objects.get(username=username)
except Member.DoesNotExist:
return HttpResponseBadRequest("Invalid username")
return HttpResponseBadRequest("Member not found")
Copy link
Member

Choose a reason for hiding this comment

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

The rest of these error messages are prefixed with something like Parameter missing: but not this one

Edit: i see more that aren't prefixed as well, i think it would be nice to have them all prefixed like that

@@ -72,7 +72,7 @@ def __init__(self, *args, **kwargs):

class QRPaymentForm(forms.Form):
member = forms.CharField(max_length=16)
amount = forms.DecimalField(min_value=50, decimal_places=2, required=False)
amount = forms.DecimalField(min_value=0.01, decimal_places=2, required=False)
Copy link
Member

Choose a reason for hiding this comment

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

I don't see the point in this change? don't we disallow payments below 50?

Copy link
Member

Choose a reason for hiding this comment

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

also when i send a request to http://localhost:8000/api/member/payment/qr?member=tester&amount=0.01 it fails, while amount=0.02 doesn't

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

Successfully merging this pull request may close these issues.

2 participants