generated from bisco/codex-bootstrap
fix(api): add basic booking throttling
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import status
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.decorators import api_view, throttle_classes
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.throttling import AnonRateThrottle
|
||||
|
||||
from shows.models import Performance
|
||||
|
||||
@@ -25,7 +26,16 @@ from .services import (
|
||||
)
|
||||
|
||||
|
||||
class ReservationCreateThrottle(AnonRateThrottle):
|
||||
scope = "reservation_create"
|
||||
|
||||
|
||||
class ReservationConfirmThrottle(AnonRateThrottle):
|
||||
scope = "reservation_confirm"
|
||||
|
||||
|
||||
@api_view(["POST"])
|
||||
@throttle_classes([ReservationCreateThrottle])
|
||||
def create_reservation(request, performance_id):
|
||||
get_object_or_404(Performance, pk=performance_id, show__is_published=True)
|
||||
|
||||
@@ -60,6 +70,7 @@ def create_reservation(request, performance_id):
|
||||
|
||||
|
||||
@api_view(["GET", "POST"])
|
||||
@throttle_classes([ReservationConfirmThrottle])
|
||||
def confirm_reservation(request):
|
||||
payload = request.query_params if request.method == "GET" else request.data
|
||||
serializer = ReservationConfirmSerializer(data=payload)
|
||||
|
||||
Reference in New Issue
Block a user