|
1 | 1 | package reviewme.highlight.service;
|
2 | 2 |
|
3 | 3 | import java.util.List;
|
4 |
| -import java.util.Set; |
5 | 4 | import lombok.RequiredArgsConstructor;
|
6 | 5 | import org.springframework.stereotype.Service;
|
7 | 6 | import org.springframework.transaction.annotation.Transactional;
|
8 | 7 | import reviewme.highlight.domain.Highlight;
|
9 | 8 | import reviewme.highlight.repository.HighlightRepository;
|
10 | 9 | import reviewme.highlight.service.dto.HighlightsRequest;
|
11 | 10 | import reviewme.highlight.service.mapper.HighlightMapper;
|
12 |
| -import reviewme.highlight.service.validator.HighlightValidator; |
13 |
| -import reviewme.review.repository.AnswerRepository; |
| 11 | +import reviewme.review.service.validator.AnswerValidator; |
14 | 12 | import reviewme.reviewgroup.domain.ReviewGroup;
|
15 | 13 |
|
16 | 14 | @Service
|
17 | 15 | @RequiredArgsConstructor
|
18 | 16 | public class HighlightService {
|
19 | 17 |
|
20 | 18 | private final HighlightRepository highlightRepository;
|
21 |
| - private final AnswerRepository answerRepository; |
22 | 19 |
|
23 |
| - private final HighlightValidator highlightValidator; |
24 | 20 | private final HighlightMapper highlightMapper;
|
| 21 | + private final AnswerValidator answerValidator; |
25 | 22 |
|
26 | 23 | @Transactional
|
27 | 24 | public void editHighlight(HighlightsRequest highlightsRequest, ReviewGroup reviewGroup) {
|
28 |
| - highlightValidator.validate(highlightsRequest, reviewGroup); |
29 |
| - List<Highlight> highlights = highlightMapper.mapToHighlights(highlightsRequest); |
30 |
| - |
31 |
| - Set<Long> answerIds = answerRepository.findIdsByQuestionId(highlightsRequest.questionId()); |
32 |
| - highlightRepository.deleteAllByAnswerIds(answerIds); |
| 25 | + List<Long> requestedAnswerIds = highlightsRequest.getUniqueAnswerIds(); |
| 26 | + answerValidator.validateQuestionContainsAnswers(highlightsRequest.questionId(), requestedAnswerIds); |
| 27 | + answerValidator.validateReviewGroupContainsAnswers(reviewGroup, requestedAnswerIds); |
33 | 28 |
|
| 29 | + List<Highlight> highlights = highlightMapper.mapToHighlights(highlightsRequest); |
| 30 | + highlightRepository.deleteByReviewGroupIdAndQuestionId(reviewGroup.getId(), highlightsRequest.questionId()); |
34 | 31 | highlightRepository.saveAll(highlights);
|
35 | 32 | }
|
36 | 33 | }
|
0 commit comments