From 65885b3a84f2b9998ddaa782cc0fd40274ebfadc Mon Sep 17 00:00:00 2001 From: ITQ Date: Mon, 4 Mar 2024 23:47:33 +0300 Subject: [PATCH] Hotfix 2 --- solution/pulse/api/posts/urls.py | 2 +- solution/pulse/api/posts/views.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/solution/pulse/api/posts/urls.py b/solution/pulse/api/posts/urls.py index fac3a0b..5347927 100644 --- a/solution/pulse/api/posts/urls.py +++ b/solution/pulse/api/posts/urls.py @@ -9,7 +9,7 @@ urlpatterns = [ name="create-post", ), path( - "/", + "/", api.posts.views.PostDetailApiView.as_view(), name="post-detail", ), diff --git a/solution/pulse/api/posts/views.py b/solution/pulse/api/posts/views.py index 7fa1ed4..aee9db7 100644 --- a/solution/pulse/api/posts/views.py +++ b/solution/pulse/api/posts/views.py @@ -1,3 +1,5 @@ +import uuid + from rest_framework import serializers, status from rest_framework.exceptions import NotFound, ValidationError from rest_framework.generics import ListAPIView @@ -26,6 +28,11 @@ class PostDetailApiView(APIView): permission_classes = [IsAuthenticated, CanAccessPost] def get(self, request, post_id): + try: + uuid.UUID(post_id) + except ValueError: + raise NotFound from None + try: post = Post.objects.get(id=post_id) self.check_object_permissions(request, post) @@ -83,13 +90,18 @@ class UserFeedListApiView(ListAPIView): limit = serializer.validated_data.get("limit") offset = serializer.validated_data.get("offset") - return user.posts.order_by("-createdAt").all()[offset : offset + limit] + return user.posts.order_by("-createdAt").all()[offset: offset + limit] class LikePostApiView(APIView): permission_classes = [IsAuthenticated, CanAccessPost] def post(self, request, post_id): + try: + uuid.UUID(post_id) + except ValueError: + raise NotFound from None + try: post = Post.objects.get(id=post_id) self.check_object_permissions(request, post) @@ -108,6 +120,11 @@ class DislikePostApiView(APIView): permission_classes = [IsAuthenticated, CanAccessPost] def post(self, request, post_id): + try: + uuid.UUID(post_id) + except ValueError: + raise NotFound from None + try: post = Post.objects.get(id=post_id) self.check_object_permissions(request, post)