Open
Conversation
Contributor
|
1번 - 주어진 조건이 그런거니까 상관없음 |
Comment on lines
+94
to
+97
| def create_comment_to_post(request): | ||
| body = request.POST | ||
| try: | ||
| post_of_comment = Post.objects.get(id=body["post_id"]) |
Contributor
There was a problem hiding this comment.
post_id를 request_body로 넘겨줘도 되는데, path param으로 넘겨줘도 될 것 같음
POST" /api/comments/1" 요런 식으로
| path("posts/<int:id>", views.retrieve_post_detail, name="retrieve_post_detail"), | ||
| path("posts/create", views.create_post, name="create_post"), | ||
| path("posts/<int:id>/put/update", views.update_post_with_put, name="update_post_with_put"), | ||
| path("comments/create", views.create_comment_to_post, name="create_comment_to_post"), |
Contributor
There was a problem hiding this comment.
여기선 표현의 한계가 있긴 한데, 나중에는 REST 하게 작성하는 방법도 익혀두면 좋을 것 같음
ex) POST /api/comments/ , POST /api/comments/1
TaeHyoungKwon
approved these changes
Jul 13, 2021
cf76a7a to
89d4674
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
테스트 작성
author,post_id,text가 있을경우 comment 작성 성공post_id,있을경우 comment 작성 실패urls.py에 path 추가create_comment_to_post메서드 작성질문
models.py를 보면 Comment 클래스에author은ForeignKey가 아닌TextField라서 테스트 작성시author에 string으로 입력했는데 괜찮은지 모르겠습니다.commit 작성시
이런식으로 commit을 작성했는데, 이 방법이 맞는건지 아니면 api에 대한 테스트코드, 모든 테스트를 통과하는 메서드를 작성하여 하나의 commit으로 작성하는게 맞는건지 궁금합니다.
이런식으로 comment index가 post에 종속되어야 한다고 생각하는데, 코드를 작성하다보니
이런식으로 comment index가 post와 관계없이 작성한 순서에 따라 할당됩니다.
이것 때문에 계속 잘못된거 같은 생각이 드는데 어떻게 고쳐야할지 몰라서 질문드립니다.