Esempio n. 1
0
    def update(self, request, pk=None):
        """Handle PUT requests for an event

        Returns:
            Response -- Empty body with 204 status code
        """
        event = Event()
        event.event_time = request.data["event_time"]
        event.location = request.data["location"]

        game = Game.objects.get(pk=request.data["gameId"])
        event.game = game
        gamer = Gamer.objects.get(pk=request.data["gamerId"])
        event.gamer = gamer

        event.save()

        return Response({}, status=status.HTTP_204_NO_CONTENT)
Esempio n. 2
0
    def create(self, request):
        """Handle POST operations for events

        Returns:
            Response -- JSON serialized event instance
        """
        gamer = Gamer.objects.get(user=request.auth.user)

        event = Event()
        event.event_time = request.data["event_time"]
        event.location = request.data["location"]
        event.gamer = gamer

        game = Game.objects.get(pk=request.data["gameId"])
        event.game = game

        try:
            event.save()
            serializer = EventSerializer(event, context={'request': request})
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        except ValidationError as ex:
            return Response({"reason": ex.message},
                            status=status.HTTP_400_BAD_REQUEST)