Skip to content

Commit c768c97

Browse files
authored
Merge pull request #19 from EventAccess/pr-test-api
Basic api draft
2 parents e750a3a + dec9d40 commit c768c97

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

backendapi/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66

77
urlpatterns = [
88
path("nfctag/<hex:tag>", views.scanned),
9+
path("test", views.api_get, name="api_get"),
910
]

backendapi/views.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from django.shortcuts import render
21
from django.views.decorators.csrf import csrf_exempt
32
from django.views.decorators.http import require_POST
43
from django.views.decorators.cache import never_cache
54
from django.http import JsonResponse
5+
from rest_framework.decorators import api_view
6+
from rest_framework.response import Response
67

78
from database.models import Attendant
89

@@ -18,3 +19,11 @@ def scanned(request, tag: bytes):
1819

1920
except Attendant.DoesNotExist:
2021
return JsonResponse({"error": "No such tag", "valid": False}, status=404)
22+
23+
24+
@api_view(["GET", "POST"])
25+
def api_get(request):
26+
if request.method == "GET":
27+
return Response({"message": "GET request received"}, status=200)
28+
elif request.method == "POST":
29+
return Response({"message": "POST request received"}, status=200)

config/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# ---
4545
"database",
4646
"backendapi",
47+
"rest_framework",
4748
]
4849

4950
MIDDLEWARE = [

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ Django[all]==5.1.3
22
django-urlconfchecks==0.11.0 # TODO: Add to CI
33
daphne==4.1.2
44
psycopg2-binary==2.9.10
5+
djangorestframework==3.15.2
6+

0 commit comments

Comments
 (0)