Commit 92d29595 authored by Bengfort's avatar Bengfort
Browse files

add ScheduleApiView for bulk get

parent 105f14f8
Pipeline #12144 passed with stages
in 1 minute and 34 seconds
......@@ -63,6 +63,8 @@ Example:
$ curl -X PUT -H 'Authorization: token CHANGEME' http://localhost:8001/api/26f4c524-4c74-4788-90c6-889dff86001d/foo/
$ curl -X GET -H 'Authorization: token CHANGEME' http://localhost:8001/api/26f4c524-4c74-4788-90c6-889dff86001d/foo/
{"datetime": "2020-11-03T07:00:00"}
$ curl -X GET -H 'Authorization: token CHANGEME' http://localhost:8001/api/26f4c524-4c74-4788-90c6-889dff86001d/
{"foo": "2020-11-03T07:00:00"}
$ curl -X DELETE -H 'Authorization: token CHANGEME' http://localhost:8001/api/26f4c524-4c74-4788-90c6-889dff86001d/foo/
```
......
......@@ -125,6 +125,20 @@ class InvitationUpdateView(UpdateView):
return response
@method_decorator(csrf_exempt, 'dispatch')
class ScheduleApiView(View):
def dispatch(self, request, *args, **kwargs):
if request.headers.get('Authorization') != 'token ' + settings.API_TOKEN:
raise PermissionDenied
return super().dispatch(request, *args, **kwargs)
def get(self, request, *args, **kwargs):
schedule = get_object_or_404(Schedule, **kwargs)
return JsonResponse({
invitation.token: invitation.datetime for invitation in schedule.invitation_set.all()
})
@method_decorator(csrf_exempt, 'dispatch')
class InvitationApiView(View):
def dispatch(self, request, *args, **kwargs):
......
......@@ -26,6 +26,7 @@ from django.views.i18n import JavaScriptCatalog
from .main.views import InvitationApiView
from .main.views import InvitationUpdateView
from .main.views import ScheduleApiView
from .main.views import ScheduleCreateView
from .main.views import ScheduleDeleteView
from .main.views import ScheduleListView
......@@ -42,6 +43,7 @@ urlpatterns = [
InvitationUpdateView.as_view(),
name='invitation',
),
path('api/<uuid:uuid>/', ScheduleApiView.as_view(), name='api-schedule'),
path(
'api/<uuid:schedule__uuid>/<token>/',
InvitationApiView.as_view(),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment