pagination comment
right type of comment response
This commit is contained in:
@@ -196,11 +196,34 @@ class AllProductsView(APIView):
|
||||
class CommentView(APIView):
|
||||
serializer_class = CommentSerializer
|
||||
permission_classes = [IsAuthenticatedOrReadOnly]
|
||||
pagination_class = StructurePagination
|
||||
@extend_schema(
|
||||
parameters=[
|
||||
OpenApiParameter(
|
||||
name="limit",
|
||||
description="Number of results to return per page (pagination).",
|
||||
required=False,
|
||||
type=OpenApiTypes.INT,
|
||||
),
|
||||
OpenApiParameter(
|
||||
name="offset",
|
||||
description="The starting position of the results (pagination).",
|
||||
required=False,
|
||||
type=OpenApiTypes.INT,
|
||||
)
|
||||
],
|
||||
responses={
|
||||
200: CommentSerializer(many=True),
|
||||
404: OpenApiTypes.OBJECT,
|
||||
},
|
||||
)
|
||||
def get(self, request, pk):
|
||||
product = get_object_or_404(ProductModel, id=pk)
|
||||
comments = product.comments.filter(show=True)
|
||||
comments_ser = self.serializer_class(instance=comments, many=True)
|
||||
return Response({'comments': comments_ser.data}, status=status.HTTP_200_OK)
|
||||
paginator = self.pagination_class()
|
||||
paginated_comments = paginator.paginate_queryset(comments, request)
|
||||
comments_ser = self.serializer_class(instance=paginated_comments, many=True)
|
||||
return paginator.get_paginated_response(comments_ser.data)
|
||||
|
||||
def post(self, request, pk):
|
||||
comment_ser = CommentSerializer(data=request.data)
|
||||
|
||||
Reference in New Issue
Block a user