Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(comment): add me.like in comment #336

Merged
merged 18 commits into from
Nov 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion hinghwa-dict-backend/article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,28 @@ def put(self, request) -> JsonResponse:
class CommentDetail(View):
# AT0405 获取评论详情
def get(self, request, id) -> JsonResponse: # 注意没有使用request,位置也是需要保留着的
# 初始化 me 的信息
me = {"is_liked": False, "is_author": False}

try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

怎么还有try在最外面,受不了了

comment = Comment.objects.get(id=id)
# 这里为什么不是 except Comment.DoesNotExist
except:
raise CommentNotFoundException(id)
return JsonResponse({"comment": comment_all(comment)}, status=200)

# 登录获取 user 信息
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用try catch 吧

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我还是不理解这里写try catch 的意义在哪里

token = token_pass(request.headers)
user = token_user(token)
except UnauthorizedException:
return JsonResponse({"comment": comment_all(comment), "me": me}, status=200)

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)


class LikeComment(View):
Expand Down
Loading