Skip to content

Commit

Permalink
feat: AT0405 add me.like return 401
Browse files Browse the repository at this point in the history
  • Loading branch information
Topology2333 committed Nov 9, 2023
1 parent 21ab819 commit 3187b2d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions hinghwa-dict-backend/article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ def get(self, request, id) -> JsonResponse:
):
raise ArticleNotFoundException()
article = article[0]
comments = [comment_normal(comment) for comment in article.comments.all()]
comments = [comment_normal(comment)
for comment in article.comments.all()]
return JsonResponse({"comments": comments}, status=200)

# AT0401 发表文章评论
Expand Down Expand Up @@ -319,13 +320,13 @@ def get(self, request, id) -> JsonResponse: # 注意没有使用request,位
token = token_pass(request.headers)
user = token_user(token)
except UnauthorizedException:
return JsonResponse({"comment": comment_all(comment), "me": me}, status=200)
return JsonResponse({"comment": comment_all(comment), "me": me}, status=401)

is_liked = comment.like_users.filter(id=user.id).exists()
is_author = (user == comment.user if user else False)

me = {"is_liked": is_liked, "is_author": is_author}

return JsonResponse({"comment": comment_all(comment), "me": me}, status=200)


Expand Down

0 comments on commit 3187b2d

Please sign in to comment.