From 5fcd950f41414878a47895e50a301df8fdc7bc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oktay=20=C3=96zel?= Date: Sun, 24 Nov 2024 11:57:45 +0300 Subject: [PATCH] get_post_details conversion from GET to POST --- backend/app/views_directory/postviews.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/app/views_directory/postviews.py b/backend/app/views_directory/postviews.py index f8318d4f..52ae3981 100644 --- a/backend/app/views_directory/postviews.py +++ b/backend/app/views_directory/postviews.py @@ -149,30 +149,29 @@ def get_posts_of_user(request): -@api_view(['GET']) +@api_view(['POST']) @permission_classes([IsAuthenticated]) def get_post_details(request): - post_id = request.data.get("post_id") - + post_id = request.data.get("post_id") + if not post_id: return Response({"detail": "Post ID is required."}, status=status.HTTP_400_BAD_REQUEST) - + post = get_object_or_404(Post, id=post_id) - + is_liked = post.liked_by.filter(id=request.user.id).exists() is_bookmarked = post.bookmarked_by.filter(id=request.user.id).exists() - comments_data = [ { "id": comment.id, - "content": comment.body, + "content": comment.body, "author": comment.author.username, "created_at": comment.created_at, - "is_liked": comment.liked_by.filter(id=request.user.id).exists(), - "like_count": comment.liked_by.count(), + "is_liked": comment.liked_by.filter(id=request.user.id).exists(), + "like_count": comment.liked_by.count(), } - for comment in post.comments.all().order_by("-created_at") + for comment in post.comments.all().order_by("-created_at") ] post_data = { @@ -181,7 +180,7 @@ def get_post_details(request): "description": post.description, "created_at": post.created_at, "like_count": post.like_count, - "tags": post.tags, + "tags": post.tags, "is_liked": is_liked, "is_bookmarked": is_bookmarked, "comments": comments_data, @@ -190,3 +189,4 @@ def get_post_details(request): return Response({"post": post_data}, status=status.HTTP_200_OK) +