From c0e71a674a7fd3542b36f0f17679108b02fbfb4a Mon Sep 17 00:00:00 2001 From: Topology2333 <118144168+Topology2333@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:17:44 +0800 Subject: [PATCH] feat(comment): add me.like in comment (#336) --- hinghwa-dict-backend/article/views.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hinghwa-dict-backend/article/views.py b/hinghwa-dict-backend/article/views.py index d8135f3a..dd108eb1 100644 --- a/hinghwa-dict-backend/article/views.py +++ b/hinghwa-dict-backend/article/views.py @@ -304,12 +304,22 @@ def put(self, request) -> JsonResponse: class CommentDetail(View): # AT0405 获取评论详情 - def get(self, request, id) -> JsonResponse: # 注意没有使用request,位置也是需要保留着的 + def get(self, request, id) -> JsonResponse: try: comment = Comment.objects.get(id=id) - except: + except Comment.DoesNotExist: raise CommentNotFoundException(id) - return JsonResponse({"comment": comment_all(comment)}, status=200) + + me = {"like": False} + + # token = token_pass(request.headers) + user = request.user + + # 是否是评论的作者,未添加 + + me["like"] = comment.like_users.filter(id=user.id).exists() + + return JsonResponse({"comment": comment_all(comment), "me": me}, status=200) class LikeComment(View):