diff --git a/backend/product/urls.py b/backend/product/urls.py index c7787e9..faad234 100644 --- a/backend/product/urls.py +++ b/backend/product/urls.py @@ -5,6 +5,5 @@ urlpatterns = [ path('', AllProductsView.as_view(), name='category-products'), path('categories', AllCategories.as_view(), name='all-categories'), path('', ProductView.as_view(), name='product-detail'), - path('/comments', CommentView.as_view(), name='product-comments'), - path('comments/', CommentView.as_view(), name='comment-delete'), + path('comments/', CommentView.as_view(), name='comment-views'), ] \ No newline at end of file diff --git a/backend/product/views.py b/backend/product/views.py index 4da0eeb..05ee93d 100644 --- a/backend/product/views.py +++ b/backend/product/views.py @@ -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)