-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
public boolean isSame(final Long memberId) { | ||
return Objects.equals(this.memberId, memberId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eq & hc
오버라이딩해도 될 것 같습니다!
There was a problem hiding this comment.
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로 감싸줘야 할것같은데 굳이라는 생각이 드네요..!
There was a problem hiding this comment.
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 객체가 같은지를 묻는 것 같아서..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 isSameMember로 변경하겠습니당!
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit이 검색해보니 동사여서..명사로 해주면 좋을 것 같습니다!
There was a problem hiding this comment.
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("스터디에 리뷰를 전체 조회한다.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 수정 및 삭제에 대한 REST DOCS 테스트도 추가해주세요!
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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+") |
There was a problem hiding this comment.
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())) { |
There was a problem hiding this comment.
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("내가 작성하지 않은 리뷰를 삭제할 수 없다.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
꼼꼼한 테스트 👍
.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+") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
중복된 URL이 너무 많은데 어떻게 하면 중복을 최대한 없앨 수 있을지 addUpAuthenticationPath의 시그니처를 변경해서 생각해보면 좋을 것 같아요.
public boolean isReviewer(final Long memberId) { | ||
return reviewer.isSame(memberId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public boolean isReviewer(final Long memberId) { | |
return reviewer.isSame(memberId); | |
} | |
public boolean isReviewer(final Long memberId) { | |
return reviewer.equals(new Reviewer(memberId)); | |
} |
이건 어떤신가요?
if (!review.isReviewer(member.getId())) { | ||
throw new UnwrittenReviewException(); | ||
} | ||
|
||
review.updateContent(editingReviewRequest.getContent()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 케이스와 전체적인 성공 케이스(얘는 인수에서 봐도 될 듯 합니다.) 하나만 봐도 될 꺼 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 바꾸니까 Review에서 단위 테스트로 충분히 가능하네요!
@DisplayName("내가 작성하지 않은 리뷰를 삭제할 수 없다.") | ||
@Test | ||
void deleteNotWriteReview() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 케이스는 Controller나 Service 테스트로 옮겨도 될 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
옮겼습니다!
|
||
@DisplayName("내가 작성하지 않은 리뷰를 수정할 수 없다.") | ||
@Test | ||
void updateNotWriteReview() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 케이스도 동일하게 Controller나 Service로 옮겨도 될 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
옮겼습니다!
요약
리뷰를 수정하거나 삭제한다.
세부사항
리뷰 수정
리뷰 삭제
close #195