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 all commits
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
16 changes: 13 additions & 3 deletions hinghwa-dict-backend/article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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:
except Comment.DoesNotExist:
raise CommentNotFoundException(id)
return JsonResponse({"comment": comment_all(comment)}, status=200)

Copy link
Member

Choose a reason for hiding this comment

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

你可以用except,但是应该在这里就处理掉了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

你可以用except,但是应该在这里就处理掉了

好了、

Copy link
Contributor Author

Choose a reason for hiding this comment

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

居然还在x

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):
Expand Down
Loading