-
Notifications
You must be signed in to change notification settings - Fork 2
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] refactor/fix: 하이라이트 검증 객체 책임 이동, 하이라이트 삭제 로직 수정 #966
Changes from all commits
9920cb7
c6a0b3b
35ec105
70d4646
c11304d
23eac25
c7a6514
59dcdbc
1ae78ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,33 @@ | ||
package reviewme.highlight.service; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import reviewme.highlight.domain.Highlight; | ||
import reviewme.highlight.repository.HighlightRepository; | ||
import reviewme.highlight.service.dto.HighlightsRequest; | ||
import reviewme.highlight.service.mapper.HighlightMapper; | ||
import reviewme.highlight.service.validator.HighlightValidator; | ||
import reviewme.review.repository.AnswerRepository; | ||
import reviewme.review.service.validator.AnswerValidator; | ||
import reviewme.reviewgroup.domain.ReviewGroup; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class HighlightService { | ||
|
||
private final HighlightRepository highlightRepository; | ||
private final AnswerRepository answerRepository; | ||
|
||
private final HighlightValidator highlightValidator; | ||
private final HighlightMapper highlightMapper; | ||
private final AnswerValidator answerValidator; | ||
|
||
@Transactional | ||
public void editHighlight(HighlightsRequest highlightsRequest, ReviewGroup reviewGroup) { | ||
highlightValidator.validate(highlightsRequest, reviewGroup); | ||
List<Highlight> highlights = highlightMapper.mapToHighlights(highlightsRequest); | ||
List<Long> requestedAnswerIds = highlightsRequest.getUniqueAnswerIds(); | ||
answerValidator.validateQuestionContainsAnswers(highlightsRequest.questionId(), requestedAnswerIds); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오호.... |
||
answerValidator.validateReviewGroupContainsAnswers(reviewGroup, requestedAnswerIds); | ||
|
||
Set<Long> answerIds = answerRepository.findIdsByQuestionId(highlightsRequest.questionId()); | ||
highlightRepository.deleteAllByAnswerIds(answerIds); | ||
List<Highlight> highlights = highlightMapper.mapToHighlights(highlightsRequest); | ||
highlightRepository.deleteByReviewGroupIdAndQuestionId(reviewGroup.getId(), highlightsRequest.questionId()); | ||
highlightRepository.saveAll(highlights); | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package reviewme.review.service.exception; | ||
|
||
import java.util.Collection; | ||
import lombok.extern.slf4j.Slf4j; | ||
import reviewme.global.exception.ReviewMeException; | ||
|
||
@Slf4j | ||
public class QuestionNotContainingAnswersException extends ReviewMeException { | ||
|
||
public QuestionNotContainingAnswersException(long questionId, Collection<Long> providedAnswerIds) { | ||
super("질문에 속하지 않는 답변이예요."); | ||
log.info("Question not containing provided answers - questionId: {}, providedAnswerIds: {}", | ||
questionId, providedAnswerIds); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package reviewme.review.service.exception; | ||
|
||
import java.util.Collection; | ||
import lombok.extern.slf4j.Slf4j; | ||
import reviewme.global.exception.ReviewMeException; | ||
|
||
@Slf4j | ||
public class ReviewGroupNotContainingAnswersException extends ReviewMeException { | ||
|
||
public ReviewGroupNotContainingAnswersException(long reviewGroupId, Collection<Long> providedAnswerIds) { | ||
super("리뷰 그룹에 속하지 않는 답변이예요."); | ||
log.info("ReviewGroup not containing provided answers - reviewGroupId: {}, providedAnswerIds: {}", | ||
reviewGroupId, providedAnswerIds); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
package reviewme.review.service.validator; | ||
|
||
import reviewme.review.domain.Answer; | ||
import java.util.Collection; | ||
import java.util.Set; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import reviewme.review.repository.AnswerRepository; | ||
import reviewme.review.service.exception.QuestionNotContainingAnswersException; | ||
import reviewme.review.service.exception.ReviewGroupNotContainingAnswersException; | ||
import reviewme.reviewgroup.domain.ReviewGroup; | ||
|
||
public interface AnswerValidator { | ||
@Component | ||
@RequiredArgsConstructor | ||
public class AnswerValidator { | ||
|
||
boolean supports(Class<? extends Answer> answerClass); | ||
private final AnswerRepository answerRepository; | ||
|
||
void validate(Answer answer); | ||
public void validateQuestionContainsAnswers(long questionId, Collection<Long> answerIds) { | ||
Set<Long> receivedAnswerIds = answerRepository.findIdsByQuestionId(questionId); | ||
if (!receivedAnswerIds.containsAll(answerIds)) { | ||
throw new QuestionNotContainingAnswersException(questionId, answerIds); | ||
} | ||
} | ||
|
||
public void validateReviewGroupContainsAnswers(ReviewGroup reviewGroup, Collection<Long> answerIds) { | ||
Set<Long> receivedAnswerIds = answerRepository.findIdsByReviewGroupId(reviewGroup.getId()); | ||
if (!receivedAnswerIds.containsAll(answerIds)) { | ||
throw new ReviewGroupNotContainingAnswersException(reviewGroup.getId(), answerIds); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package reviewme.review.service.validator; | ||
|
||
import reviewme.review.domain.Answer; | ||
|
||
public interface TypedAnswerValidator { | ||
|
||
boolean supports(Class<? extends Answer> answerClass); | ||
|
||
void validate(Answer answer); | ||
} | ||
Comment on lines
+5
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 지난 PR(#958) 에서 AnwerMapper 를 추상 클래스로만들었어요! 저는 이런 관점에서 TypedAnswerValidator 도 추상 클래스가 되어야 한다고 생각하는데, 아루는 어떻게 생각하나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
요것은 안될까용
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.
조인 하나 줄여버린 테드... 👏🏻