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] 게시글 댓글 등록, 삭제 #64

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

gdakate
Copy link
Contributor

@gdakate gdakate commented Nov 1, 2022

post /posts/{id}/comment
댓글 등록 - 성공
image

댓글 등록 - 에러 : 100글자 이상 등록한 경우
image

delete /posts/{id}/comment
댓글 삭제
스크린샷 2022-10-27 오후 12 57 08

@gdakate gdakate self-assigned this Nov 1, 2022
@gdakate gdakate requested review from jinnjuu and gksgpd97 November 1, 2022 02:05
@gdakate gdakate added the Feature 기능구현 label Nov 1, 2022
@gdakate gdakate linked an issue Nov 1, 2022 that may be closed by this pull request
Copy link
Contributor

@jinnjuu jinnjuu left a comment

Choose a reason for hiding this comment

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

댓글삭제 컨트롤러 부분 우선적으로 확인 부탁드립니다! 고생하셨습니다~!

@DeleteMapping(value="/posts/{id}/comment")
public ResponseEntity deleteComment(@PathVariable("id") Long id){
commentService.delete(id);
return ResponseEntity.ok(id);
Copy link
Contributor

Choose a reason for hiding this comment

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

삭제되었을때 상태코드 같이 리턴해주시면 좋을 것 같습니다!

}

//댓글 삭제
@DeleteMapping(value="/posts/{id}/comment")
Copy link
Contributor

@jinnjuu jinnjuu Nov 1, 2022

Choose a reason for hiding this comment

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

url 의미가 조금 맞지 않아 수정이 필요해 보입니다. 컨트롤러에 맵핑된 id (파라미터로 받은 id) 는 게시글 id 인데, 실제 서비스에서 삭제하는 id 는 댓글 id 입니다.
컨트롤러 url 을 /posts/{post-id}/comments/{comment-id} 등으로 수정하면 좋을 것 같습니다!

@Transactional
public void delete(Long id) {
Comment comment = commentRepository.findById(id).orElseThrow(() ->
new IllegalArgumentException("존재하지 않는 댓글입니다. id=" + id));
Copy link
Contributor

Choose a reason for hiding this comment

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

에러가 로그상에만 떨어지고 있는데 리턴값으로도 에러메세지나 상태코드를 넘겨주면 프론트에서 처리하기 좋을 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

controller와 service 수정하였습니다.

commentService.delete(id);
return ResponseEntity.ok(id);
@DeleteMapping(value="/posts/{post-id}/comment/{comment-id}")
public ResultResponse deleteComment(@PathVariable("post-id")Long PostId,@PathVariable("comment-id") Long CommentId){
Copy link
Contributor

Choose a reason for hiding this comment

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

변수명 첫글자는 소문자로 작성하면 좋을 듯 합니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature 기능구현
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] 게시글 댓글 등록, 삭제
2 participants