Skip to content

Commit

Permalink
get_post_details conversion from GET to POST
Browse files Browse the repository at this point in the history
  • Loading branch information
oktayozel committed Nov 24, 2024
1 parent 847468d commit 5fcd950
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions backend/app/views_directory/postviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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,
Expand All @@ -190,3 +189,4 @@ def get_post_details(request):
return Response({"post": post_data}, status=status.HTTP_200_OK)



0 comments on commit 5fcd950

Please sign in to comment.