products endpoint

This commit is contained in:
Martin Quarda 2024-10-13 09:20:11 +02:00
parent e1e1628caf
commit 96a9dc1114
2 changed files with 15 additions and 0 deletions

View File

@ -23,6 +23,7 @@ from alkatorapi.views import (
payment_result, payment_state,
invoice, upload_files,
login_status, change_racer,
products,
)
urlpatterns = [
@ -40,4 +41,5 @@ urlpatterns = [
path('api/payment_state', payment_state),
path('api/invoice', invoice),
path('api/upload_files', upload_files),
path('api/products', products)
]

View File

@ -328,6 +328,19 @@ def payment_state(request):
return HttpResponse('{"status":"failed", "reason":"Závodník neexistuje, registraci závodníka prosím opakujte."}', content_type='application/json')
def products(request):
return HttpResponse(json.dumps([
{
'name': product.name,
'description': product.description,
'img': product.img,
'price': product.price,
'quantity': product.quantity,
}
for product in Product.objects.all()
]), content_type='application/json')
def results(request):
results = []
n = 1