Added event users endpoint
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
|
from api.events import views
|
||||||
from api.events.views import EventViewSet
|
from api.events.views import EventViewSet
|
||||||
|
|
||||||
app_name = "events"
|
app_name = "events"
|
||||||
@@ -9,4 +10,5 @@ router.register("", EventViewSet)
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", include(router.urls)),
|
path("", include(router.urls)),
|
||||||
|
path("<event_id>/users/", views.EventUsersApiView.as_view(), name="users"),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,9 +1,29 @@
|
|||||||
|
from rest_framework import status
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.views import APIView
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from api.events.models import Event
|
from api.events.models import Event
|
||||||
from api.events.serializers import EventSerializer
|
from api.events.serializers import EventSerializer
|
||||||
|
from api.users.serializers import UserSerializer
|
||||||
|
|
||||||
|
|
||||||
class EventViewSet(ModelViewSet):
|
class EventViewSet(ModelViewSet):
|
||||||
queryset = Event.objects.all()
|
queryset = Event.objects.all()
|
||||||
serializer_class = EventSerializer
|
serializer_class = EventSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class EventUsersApiView(APIView):
|
||||||
|
def get(self, request, event_id): # noqa: ARG002
|
||||||
|
try:
|
||||||
|
event = Event.objects.get(pk=event_id)
|
||||||
|
except Event.DoesNotExist:
|
||||||
|
return Response(
|
||||||
|
{"error": "Event does not exist"},
|
||||||
|
status=status.HTTP_404_NOT_FOUND,
|
||||||
|
)
|
||||||
|
|
||||||
|
users = event.users.all()
|
||||||
|
serializer = UserSerializer(users, many=True)
|
||||||
|
|
||||||
|
return Response(serializer.data)
|
||||||
|
|||||||
Reference in New Issue
Block a user