-
Notifications
You must be signed in to change notification settings - Fork 4
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] 투표 도메인 리팩터링 #727
base: dev
Are you sure you want to change the base?
Conversation
- 투표시 마감기간, 선택지 옵션 검증로직 serivce계층에 위임 - 투표시 작성자 검증 로직 Vote 도메인에 위임
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.
안녕하세요 루쿠 ! 다즐입니다 ㅎㅎ
의존성을 분리하는 로직 확인했습니다 ~
몇 가지 작은 커멘트와 질문 남겨두었으니 확인해주시면 감사합니다 🙇🏻♂️
@@ -37,15 +39,19 @@ public class Vote extends BaseEntity { | |||
|
|||
@Builder | |||
private Vote(final Member member, final PostOption postOption) { | |||
validateVotingRights(member, postOption); |
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.
생성자에게 꼼꼼한 검증은 좋은 방법이라고 생각합니다 👍
한 가지 우려되는 점은 Vote
에서 Post
의존성을 가지게 되면 Vote -> Post -> PostOption -> Vote의 순환 참조가 발생할 수 있는 위험이 증가한다고 생각이 들어요.
따라서 해당 검증은 Service
계층의 비즈니스 로직에서 처리하는게 어떤지 물어보고 싶어요 :)
@@ -6,12 +6,11 @@ | |||
@Getter | |||
public enum VoteExceptionType implements ExceptionType { | |||
|
|||
CANNOT_VOTE_MY_POST(700, "해당 게시글 작성자는 투표할 수 없습니다."), | |||
CANNOT_VOTE_MY_POST(700, "게시글 작성자는 투표할 수 없습니다."), |
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.
👍👍
validateDeadline(post); | ||
validatePostOption(post, postOption); |
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.
검증은 생성 메서드와 별도로 한 곳에 묶어두는 건 어떨까요?!
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.
숨겨진 게시글에 대한 검증도 있으면 좋을 것 같아요 ㅎㅎ
|
||
@Test | ||
@DisplayName("본인의 게시글에 투표하는 경우 예외 발생") | ||
void vote1() { |
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.
팀 컨벤션에 맞게 영어 테스트명도 한글 테스트명에 알맞게 작명하면 좋을 것 같아요 ~
.isInstanceOf(BadRequestException.class) | ||
.hasMessage("이미 참여한 투표입니다."); | ||
} | ||
|
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.
해당 선택지는 아니지만 해당 게시글의 다른 선택지에 투표한 상황에 대한 테스트와 숨겨진 게시글을 투표한 상황에 대한 테스트도 있으면 더욱 좋을 것 같습니다 🤓
class vote { | ||
|
||
@Test | ||
@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.
성공 메서드명에서만 .
을 넣으신 이유가 궁금합니다 !
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 Vote vote = Vote.builder() | ||
.member(member) | ||
.postOption(postOption) | ||
.build(); | ||
postOption.addVote(vote); | ||
return vote; |
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.
createVote메서드에선 postOption 셋팅을 제외한 Vote를 만드는 로직만 남겨두고, 양방향 관계를 맺어주는 건 이미 postOption.addVote(vote) 여기서 해주고 있으니 차라리 밑의 예시처럼 구현하는 것은 어떨까요?
private Vote createVote(final Member member) {
return Vote.builder()
.member(member)
.build();
}
그리고 vote 메서드에서
postOption.addVote(vote);
이 코드를 진행하는 형식입니다.
createVote 메서드의 파라미터 수도 줄일 수 있고, 코드의 흐름을 파악하기 더 수월할 것 같아요 :)
@@ -72,8 +94,8 @@ public void changeVote( | |||
.orElseThrow(() -> new NotFoundException(PostOptionExceptionType.NOT_FOUND)); | |||
|
|||
voteRepository.delete(originVote); | |||
final Vote vote = post.makeVote(member, newPostOption); | |||
voteRepository.save(vote); | |||
final Vote newVote = createVote(member, post, newPostOption); |
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 | ||
int count = voteRepository.countByMember(member); | ||
assertThat(count).isEqualTo(1); |
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.
.isEqualTo(1); 대신 isOne(); 은 어떨까요
final PostOption postOption = postOptionRepository.findById(postOptionId) | ||
.orElseThrow(() -> new NotFoundException(PostOptionExceptionType.NOT_FOUND)); | ||
|
||
final Vote vote = post.makeVote(member, postOption); | ||
validateAlreadyVoted(member, post); | ||
final Vote vote = createVote(member, post, postOption); | ||
voteRepository.save(vote); |
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.
이 부분은 생략해도 변경 감지에 의해 vote가 자동으로 insert 될 것 같아요
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: #514
📝 작업 요약
⏰ 소요 시간
3시간
🔎 작업 상세 설명
🌟 논의 사항