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

[Refactor #153] 자유게시판, 성지순례 인증글 response DTO, status 수정 #154

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

jorippppong
Copy link
Contributor

@jorippppong jorippppong commented Sep 24, 2024

📄 Work Description

  • 자유게시판, 성지순례 인증글 response DTO, status 수정

⚙️ ISSUE

📷 Screenshot

스크린샷 2024-09-24 오후 4 01 58

💬 To Reviewers

기존의 코드에서는 성공적인 응답일 경우, 모두 200 응답값을 반환했습니다.
Get / Post는 반환할 리소스가 있지만, Put / Patch / Delete의 경우 반환할 리소스가 없는 경우가 있습니다. 이 경우 204 NO CONTENT를 반환하여 클라이언트에게 반환할 리소스가 없음을 명시할 수 있습니다.
또한 response DTO class를 공유하는 과정에서 쓸모없는 값들이 추가가 되어서, 이를 제거했습니다.

<응답값이 204로 수정되면서, response DTO가 없어진 API>

  • PUT posts/guestbooks/comments/{comment_id}
  • DELETE posts/guestbooks/comments/{comment_id}
  • PUT posts/free/comments/{comment_id}
  • DELETE posts/free/comments/{comment_id}
  • DELETE posts/guestbooks/{guestbook_id}
  • PATCH posts/guestbooks/{guestbook_id}
  • DELETE posts/free/{post_id}
  • PATCH posts/free/{post_id}

<response DTO가 수정된 API>

  • POST /posts/free/{post_id}/like
  • POST /posts/guestbooks/{post_id}/like
  • POST /posts/guestbooks/{pilgrimage_id}
  • POST /posts/free/{post_id}/comments
  • POST /posts/guestbooks/{guestbook_id}/comments

노션에 명시한 값들은 휴먼 에러가 있을 가능성이 높아서, 스웨거로 확인하는 것이 신뢰성이 높은 것 같습니다!

🔗 Reference

@jorippppong jorippppong added the ♻️ refactor code refactoring label Sep 24, 2024
@jorippppong jorippppong self-assigned this Sep 24, 2024
Copy link
Contributor

@ppparkta ppparkta left a comment

Choose a reason for hiding this comment

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

프론트와의 협업에 용이하게 너무나 좋은 방향으로 수정된 것 같습니다. http status에 대해 고민해본 적이 없었던 것 같은데, 수정해주신 코드가 많은 도움이 되었습니다. 궁금한 점이 몇 개 있어서 질문 달아두었는데, 바쁘시면 직접 찾아보겠습니다! 너무 고생많으셨습니다!

Comment on lines +69 to +71
@ApiResponses(value = {
@ApiResponse(responseCode = "204")
})
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.

네! 해당 코드를 추가하지 않으면 코드에는 204로 설정해도, 스웨거에서는 200으로 뜨더라구요.

commentCommandService.modifyComment(member, commentId, dto.getContent());
return new ResponseEntity<>(
PostResponseDto.SuccessResponseDto.builder().message("댓글 성공적으로 수정했습니다.").build(),
HttpStatus.OK
HttpStatus.NO_CONTENT
Copy link
Contributor

Choose a reason for hiding this comment

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

http status에 대한 이해 없이 개발을 하다보니 놓친 부분이었는데, 유리님이 코드 수정해주셔서 저도 다른 api를 웹 규약에 맞게 수정해야겠다는 생각이 들었네요. 감사합니다!

@DeleteMapping("/comments/{comment_id}")
public ResponseEntity<PostResponseDto.SuccessResponseDto> deleteGuestBookComment(
public ResponseEntity<?> deleteGuestBookComment(
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

@jorippppong jorippppong Sep 24, 2024

Choose a reason for hiding this comment

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

?는 body에 어떤 타입도 다 반환할 수 있다는 의미여서 ?로 처리했습니다.
"204"가 반환할 리소스가 없다는 없다는 뜻이니까 ? 보다는 Void 로 처리하는게 직관성이 좋은 것 같네요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

후딱 수정해서 커밋 추가할께요!

@ppparkta
Copy link
Contributor

리뷰해주신 내용들 모두 이해됐습니다. 감사합니다!
리팩토링에 대해 고민하고 바로 개선해나가는 모습 멋있어요~~~

Copy link
Member

@JungYoonShin JungYoonShin left a comment

Choose a reason for hiding this comment

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

고민 많이 하시고 리팩하신 것 같네요🥺 너무 수고하셨습니다!

추가적으로 궁금한 부분은 댓글 달아두었습니다!

Comment on lines 96 to 99
return new ResponseEntity<>(
PostResponseDto.SuccessResponseDto.builder().message("성지순례 인증글을 성공적으로 수정했습니다.").build(),
HttpStatus.OK
HttpStatus.NO_CONTENT
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Spring은 ResponseEntity를 더 쉽게 생성하기 위한 빌더 메서드를 제공하고 있는데요!

취향 차이일 수도 있지만 해당 코드를 return ResponseEntity.noContent().build()로 작성할 수도 있을 것 같아요~!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오! 빌더 좋은 것 같아요!

Comment on lines 115 to 125
@PostMapping("/{guestbook_id}/like")
public ResponseEntity<PostResponseDto.SuccessResponseDto> modifyGuestBookLike(
public ResponseEntity<PostResponseDto.LikeSuccessResponseDto> modifyGuestBookLike(
@PathVariable("guestbook_id") Long guestbookId
){
Member member = securityUtil.getUser();
String message = likedPostService.modifyGuestBookLike(member, guestbookId);
Long likedId = likedPostService.modifyGuestBookLike(member, guestbookId);
return new ResponseEntity<>(
PostResponseDto.SuccessResponseDto.builder().message(message).build(),
PostResponseDto.LikeSuccessResponseDto.builder().likedId(likedId).build(),
HttpStatus.OK
);
}
Copy link
Member

Choose a reason for hiding this comment

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

message 대신, 생성된 likeId만 담아서 보내는 방향으로 리팩하신 이유가 궁금해요! ㅎㅎ

Copy link
Contributor Author

Choose a reason for hiding this comment

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

해당 API는 특정 게시글에 좋아요, 좋아요 취소를 제공하는 기능입니다! 기존의 방식에는 "좋아요를 눌렀습니다", "좋아요를 취소했습니다."를 message에 전달했는데, 해당 값은 프론트에서 유의미 하게 쓰이는 값이 아니라서 message는 제거를 했습니다. LikedId는 Post 행위인 만큼 생성된 자원의 id를 반환하고자 추가를 했는데, 사실 likedId를 사용하는 API가 없네요..허헣ㅎㅎ

@jorippppong jorippppong merged commit ff444b6 into develop Sep 25, 2024
1 check passed
@jorippppong jorippppong deleted the refactor/#153 branch September 25, 2024 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♻️ refactor code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR] 자유게시글, 성지순례 인증글 수정&삭제 response DTO, status 수정
3 participants