This commit is contained in:
ITQ
2024-03-04 23:47:33 +03:00
parent 79f0aaaaa6
commit 65885b3a84
2 changed files with 19 additions and 2 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ urlpatterns = [
name="create-post",
),
path(
"/<uuid:post_id>",
"/<str:post_id>",
api.posts.views.PostDetailApiView.as_view(),
name="post-detail",
),
+17
View File
@@ -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)
@@ -90,6 +97,11 @@ 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)