-
Notifications
You must be signed in to change notification settings - Fork 9
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
lin594
merged 18 commits into
e-dialect:develop
from
Topology2333:AT0405_me_like_author
Nov 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
21ab819
feat: AT0405(comment) add me.like & me.is_author
Topology2333 39ed02f
Merge branch 'e-dialect:develop' into AT0405_me_like_author
Topology2333 3187b2d
feat: AT0405 add me.like return 401
Topology2333 38180a7
Merge remote-tracking branch 'refs/remotes/origin/AT0405_me_like_auth…
Topology2333 858c082
style: lint views.py
Topology2333 851d673
refactor: combine 2 try-catches
Topology2333 a1ffe30
refactor: delete unauthorized exception
Topology2333 124bc72
refactor: all raise comment-not-found
Topology2333 f59a39e
refactor: add unauthorized user exception
Topology2333 fce79ab
refactor: combine 2 try-catches
Topology2333 48fbebf
pass UnauthorizedException
Topology2333 d95b4ba
refactor: pass exception
Topology2333 e8a06a9
Merge branch 'e-dialect:develop' into AT0405_me_like_author
Topology2333 297fa27
refactor: pass UnauthorizedException
Topology2333 10e8554
refactor: deal with UnauthorizedException
Topology2333 1484805
style: change the way authentication function
Topology2333 439e313
style: pre-test exception
Topology2333 d7fbff9
style: relint
Topology2333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
comment = Comment.objects.get(id=id) | ||
# 这里为什么不是 except Comment.DoesNotExist | ||
except: | ||
raise CommentNotFoundException(id) | ||
return JsonResponse({"comment": comment_all(comment)}, status=200) | ||
|
||
# 登录获取 user 信息 | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不用try catch 吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
怎么还有try在最外面,受不了了