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

[BE] issue195: 리뷰 수정 및 삭제 #198

Merged
merged 13 commits into from
Aug 4, 2022

Conversation

sc0116
Copy link
Collaborator

@sc0116 sc0116 commented Aug 3, 2022

요약

리뷰를 수정하거나 삭제한다.

세부사항

리뷰 수정

  • 리뷰를 수정한다.
  • 내가 작성하지 않은 리뷰를 수정하려는 경우 예외를 반환한다.

리뷰 삭제

  • 리뷰를 삭제한다.
  • 내가 작성하지 않은 리뷰를 삭제하려는 경우 예외를 반환한다.

close #195

@sc0116 sc0116 self-assigned this Aug 3, 2022
@sc0116 sc0116 added 🚀 feature New feature or request 🖥 backend New backend feature labels Aug 3, 2022
@sc0116 sc0116 linked an issue Aug 3, 2022 that may be closed by this pull request
Comment on lines 20 to 22
public boolean isSame(final Long memberId) {
return Objects.equals(this.memberId, memberId);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

eq & hc 오버라이딩해도 될 것 같습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

저도 디우의 말을 듣고 만들까 고민했는데 Review에서 Reviewer 두개를 비교하는게 아니라 Reviewer 객체한테 memberId 넘겨주고 비교하는 거라서 기존이 더 깔끔할 것 같은데 어떻게 생각하세요?
만약 eq&hc로 비교하려면 Review에서 memberId를 Reviewer로 감싸줘야 할것같은데 굳이라는 생각이 드네요..!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Reviewer reviewer = new Reviewer(1L);
Reviewer anotherReviewer = new Reviewer(2L);

reviewer.equals(anotherReviewer);

위의 코드 보다는

Reviewer reviewer = new Reviewer(1L);
Long memberId = 2L;

reviewer.isSame(memberId);

이 더 깔끔할 것 같다라고 이해하면 될까요??

현재 기능 동작같은 경우에는 둘이 논리적으로 동일하게 동작하고 있고, 인자로 넘겨주는 memberId 가 리뷰를 작성한 사람의 memberId 와 같은가라는 입장에서 보았을 때, 짱구의 말대로 eq&hc(동일한 객체인가 보다는 리뷰를 작성한 사람의 memberId와 같은가 라는 관점으로 보았을 때) 는 적절하지 못할수도 있겠다는 생각이 드네요!

그렇다면, isSame 이 아니라 isSameMember(예시) 와 같은 네이밍이면 보다 명확할 것 같네요!!
(개인적으로 isSame은 Reviewer 객체가 같은지를 묻는 것 같아서..)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

앗 isSameMember로 변경하겠습니당!

Copy link
Collaborator

@tco0427 tco0427 left a comment

Choose a reason for hiding this comment

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

put 응답 포함해서 몇가지 사소한 부분 코멘트 남겼습니다~_~

@NoArgsConstructor
@AllArgsConstructor
@Getter
public class EditReviewRequest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Edit이 검색해보니 동사여서..명사로 해주면 좋을 것 같습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

앗..! Editing으로 수정했습니다!

@@ -43,7 +43,7 @@ void create() throws Exception {
@DisplayName("스터디에 리뷰를 전체 조회한다.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

리뷰 수정 및 삭제에 대한 REST DOCS 테스트도 추가해주세요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

감사함둥 ㅠㅠㅠㅠ 진짜 생각도 못했네요..!

import com.woowacourse.moamoa.common.exception.BadRequestException;

public class UnwrittenReviewException extends BadRequestException {
public UnwrittenReviewException() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

한 칸 띄어도 될 것 같아요

.addUpAuthenticationPath(HttpMethod.GET, "/api/my/studies")
.addUpAuthenticationPath(HttpMethod.PUT, "/api/studies/\\d+/reviews/\\d+")
.addUpAuthenticationPath(HttpMethod.DELETE, "/api/studies/\\d+/reviews/\\d+")
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

final Review review = reviewRepository.findById(reviewId)
.orElseThrow(ReviewNotFoundException::new);

if (!review.isReviewer(member.getId())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

밑에 같은 검증을 하는 코드가 있어서, 메서드로 분리해도 좋을 것 같아요 !

.then().statusCode(HttpStatus.NO_CONTENT.value());
}

@DisplayName("내가 작성하지 않은 리뷰를 삭제할 수 없다.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

꼼꼼한 테스트 👍

Comment on lines -17 to +20
.addUpAuthenticationPath(HttpMethod.POST, "/api/studies", "/api/studies/\\d+/reviews")
.addUpAuthenticationPath(HttpMethod.POST, "/api/studies", "/api/studies/\\d+/reviews", "/api/studies/\\d+/reviews/\\d+")
.addUpAuthenticationPath(HttpMethod.GET, "/api/my/studies")
.addUpAuthenticationPath(HttpMethod.PUT, "/api/studies/\\d+/reviews/\\d+")
.addUpAuthenticationPath(HttpMethod.DELETE, "/api/studies/\\d+/reviews/\\d+")
Copy link
Collaborator

Choose a reason for hiding this comment

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

중복된 URL이 너무 많은데 어떻게 하면 중복을 최대한 없앨 수 있을지 addUpAuthenticationPath의 시그니처를 변경해서 생각해보면 좋을 것 같아요.

Comment on lines 43 to 45
public boolean isReviewer(final Long memberId) {
return reviewer.isSame(memberId);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
public boolean isReviewer(final Long memberId) {
return reviewer.isSame(memberId);
}
public boolean isReviewer(final Long memberId) {
return reviewer.equals(new Reviewer(memberId));
}

이건 어떤신가요?

Comment on lines 49 to 53
if (!review.isReviewer(member.getId())) {
throw new UnwrittenReviewException();
}

review.updateContent(editingReviewRequest.getContent());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (!review.isReviewer(member.getId())) {
throw new UnwrittenReviewException();
}
review.updateContent(editingReviewRequest.getContent());
review.updateContent(new Reviewer(member.getId()), editingReviewRequest.getContent());

위와 같이 하고 updateContent 안에서 예외를 던지도록 하는게 좋아 보입니다.
그 이유는 updateContent 안에 넣어주면 domain 단위 테스트에서 예외가 던져지는 케이스를 확인할 수 있어요.
controller나 service 테스트에서는 NotFound 케이스와 전체적인 성공 케이스(얘는 인수에서 봐도 될 듯 합니다.) 하나만 봐도 될 꺼 같아요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이렇게 바꾸니까 Review에서 단위 테스트로 충분히 가능하네요!

Comment on lines 151 to 153
@DisplayName("내가 작성하지 않은 리뷰를 삭제할 수 없다.")
@Test
void deleteNotWriteReview() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 케이스는 Controller나 Service 테스트로 옮겨도 될 것 같습니다.

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("내가 작성하지 않은 리뷰를 수정할 수 없다.")
@Test
void updateNotWriteReview() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 케이스도 동일하게 Controller나 Service로 옮겨도 될 것 같습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

옮겼습니다!

@verus-j verus-j merged commit 245d832 into develop Aug 4, 2022
@verus-j verus-j deleted the feat/195-update-or-delete-review branch August 4, 2022 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🖥 backend New backend feature 🚀 feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BE] 리뷰 수정 및 삭제
4 participants