backend/passfinder/recomendations/api/views.py

27 lines
1.1 KiB
Python
Raw Normal View History

2023-05-21 13:37:21 +03:00
from typing import Any
from rest_framework import viewsets, mixins
from rest_framework.request import Request
from rest_framework.response import Response
from passfinder.events.models import Event
from passfinder.events.api.serializers import EventSerializer
from random import choice
from rest_framework.decorators import action
from rest_framework.response import Response
from .serializers import TinderProceedSerializer
class TinderView(viewsets.GenericViewSet):
serializer_class = EventSerializer
model = Event
queryset = Event.objects.all()
@action(methods=['GET'], detail=False, serializer_class=EventSerializer)
def start(self, request: Request, *args: Any, **kwargs: Any):
event = EventSerializer(choice(Event.objects.all()))
return Response(data=event.data, status=200)
@action(methods=['POST'], detail=True, serializer_class=TinderProceedSerializer)
def proceed(self, request: Request, *args: Any, **kwargs: Any):
event = EventSerializer(choice(Event.objects.all()))
return Response(data={'event': event.data}, status=200)