-
Notifications
You must be signed in to change notification settings - Fork 0
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] 리뷰 진행하기 #24
Conversation
.orElseGet(() -> ReviewRecord.of(writer, reviewForm, request)); | ||
} | ||
|
||
private Member findMemberById(Long 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.
Review도메인과는 관련이 없는 메소드인 것 같아서 MemberService를 DI 받아서 사용하는 방식은 어떠신가요?
findById는 다른 곳에서도 많이 사용될 것 같은데, 멤버를 찾지 못해서 발생하는 예외사항 처리도 멤버 서비스에서 해주고, Review Service에서는 아예 신경쓰지 않으면 Review도메인이라는 관심사에 조금더 집중이 될 것 같아요.
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.
이 부분은 말씀하셨던 Repository에서 예외처리도 해주는 방식으로 수정해보겠습니다.
https://ttl-blog.tistory.com/1467
request.getReviewFormId()) | ||
); | ||
memberIdList.forEach(reviewerId -> { | ||
findMemberById(reviewerId); |
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.
findMemberById의 목적이 2가지로 사용되고 있는 것 같은데 맞을까요?
- ID에 해당하는 멤버 인스턴스 Return
- ID에 해당하는 멤버가 있는지 Validation
기존 메서드 이름은 Validation하는 목적이 포함이 안되어 있는 것 같아서
두가지 목적으로 같이 사용하신다면 findMemberByIdOrElseThrow()
나 너무 길게 느껴지신다면 findMemberOrElseThrow()
는 어떠신가요?
후자의 경우 파라미터로 넘어가는 memberId로 Id로 멤버를 찾는다는 것이 명시적인 것 같아서 생략해도 되지 않나 싶어서요
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.
alarmService에서 reviewId에 대한 유효성 검사를 하고 있는 것 같은데, 더블체크를 위해 추가해주신걸까요?
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.
alarmService에서 reviewId에 대한 유효성 검사를 하고 있는 것 같은데, 더블체크를 위해 추가해주신걸까요?
alarmService에서 reviewId 유효성 검사하는 로직이 있다는 것을 까먹었네요.. ReviewService의 유효성 검사용 findMemberById는 지우도록 하겠습니다
|
||
Member writer = findMemberById(memberId); | ||
ReviewForm reviewForm = findReviewFormById(reviewFormId); | ||
ReviewRecord reviewRecord = getOrCreateReviewRecord(writer, reviewForm, request); |
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.
깔끔한 extract method군요 👍 👍
savedRecord.update(request); | ||
return savedRecord; | ||
}) | ||
.orElseGet(() -> ReviewRecord.of(writer, reviewForm, request)); |
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문이 들어가 있어서 이부분도 extract Method를 해주면 좋을 것 같네요! 비공개 메서드가 좀 많아 지는군요
private ReviewRecord getOrCreateReviewRecord(Member writer, ReviewForm reviewForm, ReviewSaveRequest request) {
return reviewRecordRepository.findByReviewForm(reviewForm)
.map(savedRecord -> updateIfDraft(savedRecord, request))
.orElseGet(() -> ReviewRecord.of(writer, reviewForm, request));
}
private ReviewRecord updateIfDraft(ReviewRecord savedRecord, ReviewSaveRequest request) {
validateIfAlreadySubmitted(savedRecord);
savedRecord.update(request);
return savedRecord;
}
private void validateIfAlreadySubmitted(ReviewRecord savedRecord) {
if (!savedRecord.getIsDraft()) {
throw new RestApiException(ReviewErrorCode.ALREADY_SUBMITTED);
}
}
private List<ChoiceQuestion> findChoiceQuestionsByCategories(List<CategoryType> categoryTypes) { | ||
|
||
return categoryTypes.stream() | ||
.flatMap(category -> choiceQuestionRepository.findByCategoryType(category) |
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.
분리해야하는 거 맞습니다..! 확인해보니 지금 코드에서 flatMap을 써서 모든 카테고리 질문들을 하나로 합친 다음에, Response를 만들 때 groupby로 카테고리별로 다시 묶고있네요.. 수정하겠습니다
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.
수고하셨습니다~!
✏️ Description
🙏🏻 To Reviewers
💡 Issue Number