Only throttle POST, not GET. Fix documentation.
-import json
from cccatalog.api.serializers.list_serializers import ImageListSerializer
+from drf_yasg.utils import swagger_auto_schema
+from rest_framework import serializers
from rest_framework.views import APIView
from rest_framework.throttling import UserRateThrottle
+from rest_framework.decorators import throttle_classes
from rest_framework.response import Response
-class ListThrottler(UserRateThrottle):
+class ListCreateThrottler(UserRateThrottle):
rate = '30/day'
class List(APIView):
- """
- Create a public collection of images. Return the ID of the list.
+ class _PostResponse(serializers.Serializer):
+ id = serializers.IntegerField(
+ help_text="The ID of the new list."
+ )
- To prevent abuse, only up to 30 lists can be made by a single user per day,
- and lists can only have up to 500 items.
+ @swagger_auto_schema(operation_id="list_create",
+ responses={
+ 201: _PostResponse,
+ 400: "Bad Request"
+ })
+ @throttle_classes([ListCreateThrottler])
+ def post(self, request, format=None):
"""
- throttle_classes = (ListThrottler,)
- serializer_class = ImageListSerializer
+ Create a public collection of images. Returns the ID of the newly
+ created list.
- def post(self, request, format=None):
+ To prevent abuse, only up to 30 lists can be made by a single user per
+ day, and lists can only contain up to 500 items. Additionally, all
+ input primary keys must be valid. If any of these constraints are
+ violated, a validation error is returned.
+ """
serialized = ImageListSerializer(data=request.data)
if not serialized.is_valid():
return Response(
@@ -34,3 +47,6 @@ class List(APIView):
'id': list_id
}
)
+
+ def get(self, request, format=None):
+ pass
\ No newline at end of file
