Skip to content

Commit

Permalink
Merge pull request #553 from bounswe/BACKEND-550
Browse files Browse the repository at this point in the history
like_unlike problem solution
  • Loading branch information
skywllker authored Nov 22, 2024
2 parents df216ae + 6234902 commit a8884cb
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions backend/app/views_directory/postviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ def like_post(request):
object_type="Post",
object_id=post.id,
)
return Response({"detail": "Post liked successfully.", "like_count": post.like_count}, status=status.HTTP_200_OK)

# Include like and bookmark status in the response
is_liked = request.user in post.liked_by.all()
is_bookmarked = post.bookmarked_by.filter(id=request.user.id).exists()

return Response(
{
"detail": "Post liked successfully.",
"like_count": post.like_count,
"is_liked": is_liked,
"is_bookmarked": is_bookmarked,
},
status=status.HTTP_200_OK
)

@api_view(['POST'])
@permission_classes([IsAuthenticated])
Expand All @@ -44,7 +57,20 @@ def unlike_post(request):
post.liked_by.remove(request.user)
post.like_count = post.liked_by.count()
post.save()
return Response({"detail": "Post unliked successfully.", "like_count": post.like_count}, status=status.HTTP_200_OK)

# Include like and bookmark status in the response
is_liked = request.user in post.liked_by.all()
is_bookmarked = post.bookmarked_by.filter(id=request.user.id).exists()

return Response(
{
"detail": "Post unliked successfully.",
"like_count": post.like_count,
"is_liked": is_liked,
"is_bookmarked": is_bookmarked,
},
status=status.HTTP_200_OK
)

@api_view(['POST'])
@permission_classes([IsAuthenticated])
Expand Down

0 comments on commit a8884cb

Please sign in to comment.