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

Feature/#83 댓글 대댓글 crud api 구현 #97

Merged
merged 25 commits into from
Jul 27, 2023

Conversation

java-saeng
Copy link
Collaborator

#️⃣연관된 이슈

📝작업 내용

댓글 관련 CRUD API 를 구현해습니다.

예상 소요 시간 및 실제 소요 시간

예상 시간 : 수요일 오후 6시
실제 소요 시간 : 수요일 오전 12시

💬리뷰 요구사항

코드 잘 읽히시는지, 제대로 작성된 것 같은지 확인 부탁드립니다.

- 테스트에서 createdAt, updatedAt을 등록하지 못하기 때문에 null 제약조건
- createdAt, updatedAt 을 nullable 하는 것으로 수정

#83
@java-saeng java-saeng added Backend 백엔드 관련 이슈 기능 추가 새로운 기능 추가 및 기존 기능 변경 labels Jul 25, 2023
@java-saeng java-saeng self-assigned this Jul 25, 2023
@java-saeng java-saeng changed the base branch from main to backend-main July 25, 2023 15:10
Copy link
Collaborator

@hong-sile hong-sile left a comment

Choose a reason for hiding this comment

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

전체적으로 통일성이 있어서 확인하긴 편했습니다.

몇몇 커멘트 남겼으니 확인해주세요.

final Event savedEvent
) {
final Comment savedComment = commentRepository.save(
new Comment(savedEvent, null, member, commentAddRequest.getContent())
Copy link
Collaborator

Choose a reason for hiding this comment

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

요건 취향이긴 한데, 한번 정적팩터리 메서드를 정의해서
RootComment를 만들 때랑 ChildComment 만들 때랑 다른 메서드를 사용하게 하는 것은 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현장 리뷰 완료요~~

commentCommandService.delete(commentId, member);
}

@PatchMapping("/comments/{comment-id}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment 내용을 완전히 덮어씌우는 거라면
Put 은 어떤가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현장 리뷰 완료요~~

@DisplayName("delete() : 댓글을 삭제할 때, 로그인 한 본인의 댓글이 아니면 CAN_NOT_DELETE_COMMENT 가 발생합니다.")
void test_delete_canNotDeleteComment() throws Exception {
//given
final Member 댓글_작성자 = memberRepository.findById(1L).get();
Copy link
Collaborator

Choose a reason for hiding this comment

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

댓글 작성자를 모든 테스트에서 쓴다면 필드 변수로 빼보는 건 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현장 리뷰 완료요~~

new Comment(event2, null, member, "부모댓글1")
);

final long eventId = 2L;
Copy link
Collaborator

Choose a reason for hiding this comment

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

나중에 event 관련된 테스트가 생기면 auto_increment 때문에 터질 것 같아요.
event의 getId로 eventId를 세팅하면 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현장 리뷰 완료요~~

Copy link
Collaborator

@hyeonjerry hyeonjerry left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!
크게 수정할 점은 보이지 않습니다.

@Service
@RequiredArgsConstructor
@Transactional
public class CommentCommandService {
Copy link
Collaborator

Choose a reason for hiding this comment

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

혹시 Command가 나타내는게 Query 이외의 모든 동작인가요? 지금은 Query와 Command밖에 없어서 쉽게 예측이 되지만 더 늘어난다면 Command에 어떤 동작이 있는지 예측하기 어려울 것 같아요.
혹시 CommentWriteService, CommentDeleteService 이런 식으로 나누는건 어떠신가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현장 리뷰 완료요~~


@DeleteMapping("/comments/{comment-id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void delete(@PathVariable("comment-id") final Long commentId, final Member member) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

이건 개인적으로 궁금해서 여쭤보는건데 혹시 comment-id로 받으시는 이유가 있으신가요?
commentId로 받으면 PathVariable에 name을 생략할 수 있는데 굳이 comment-id로 받아서 name을 명시한 이유가 있는지 궁금합니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현장 리뷰 완료요~~


private final String content;

private CommentModifyRequest() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

혹시 이게 왜 필요한지 알 수 있을까요?
없으면 테스트가 터지는데 다른 Request DTO들은 없어도 되는데 이 친구만 특별하게 있어야 하는 이유가 궁금합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현장 리뷰 완료요~~

@Getter
public class CommentResponse {

private static final String DELETE_COMMENT_CONTENT = "삭제된 댓글입니다.";
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 상수가 사용되고 있는 곳을 찾을 수 없는데 혹시 어디서 사용하는 건가요?
isDeleted를 통해 true일 경우 이 값으로 대체하는 로직이 빠진걸까요?

"해당 댓글은 존재하지 않습니다."
),

CAN_NOT_DELETE_COMMENT(
Copy link
Collaborator

Choose a reason for hiding this comment

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

이건 개인적인 의견인데 갑자기 생각이 나서 코멘트 달아둡니다.
혹시 NOT_FOUND처럼 FORBIDDEN으로 http 상태 메시지로 통일하는건 어떠신가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현장 리뷰 완료요~~

),

CAN_NOT_MODIFY_DELETED_COMMENT(
HttpStatus.FORBIDDEN,
Copy link
Collaborator

Choose a reason for hiding this comment

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

이건 인가의 문제가 아니라 클라이언트의 잘못된 요청이므로 BAD_REQUEST가 더 좋을 것 같은데 우르는 어떻게 생각하시나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현장 리뷰 완료요~~

@@ -36,6 +38,8 @@ void findAllByMemberId() throws Exception {
.map(MemberActivity::getId)
.collect(toUnmodifiableList());

System.out.println("memberCareerIds.size() = " + memberCareerIds.size());
Copy link
Collaborator

Choose a reason for hiding this comment

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

혹시 콘솔 출력을 추가하신 이유가 있으신가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

현장 리뷰 완료요~~

Copy link
Collaborator

@amaran-th amaran-th left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!
코멘트 몇 개 남겼으니 확인해주시면 감사하겠습니다~

CAN_NOT_MODIFY_COMMENT(
HttpStatus.FORBIDDEN,
"댓글 작성자 외에는 수정할 수 없습니다."
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

개인적으로 CAN_NOT_DELETE_COMMENT, CAN_NOT_MODIFY_COMMENT보다는 INVALID_AUTHORITY가 원인을 파악하기에 좀 더 직관적일 것 같다는 생각이 듭니다!

final Comment comment = commentRepository.findById(commentId)
.orElseThrow(() -> new CommentException(NOT_FOUND_COMMENT));

validateSameWriter(loginMember, comment, CAN_NOT_DELETE_COMMENT);
Copy link
Collaborator

Choose a reason for hiding this comment

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

혹시 CAN_NOT_DELETE_COMMENT 예외 타입을 validateSameWriter() 메서드에서 직접 사용하지 않고 매개변수로 넘겨주신 이유가 있나요??
조금 불필요한 작업으로 느껴져서요

@Getter
public class CommentResponse {

private static final String DELETE_COMMENT_CONTENT = "삭제된 댓글입니다.";
Copy link
Collaborator

Choose a reason for hiding this comment

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

이제 사용되고 있지 않은 상수인 것 같으니 지워줘도 될 것 같습니다!

@java-saeng
Copy link
Collaborator Author

현장 리뷰 완료

@java-saeng java-saeng merged commit 1d40df8 into backend-main Jul 27, 2023
1 check passed
@hyeonjerry hyeonjerry deleted the Feature/#83-댓글_대댓글_CRUD_API_구현 branch July 31, 2023 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend 백엔드 관련 이슈 기능 추가 새로운 기능 추가 및 기존 기능 변경
Projects
Status: Archive
Development

Successfully merging this pull request may close these issues.

4 participants