|
22 | 22 | @Transactional
|
23 | 23 | public class BasicAdminMajorQuestionMakeService implements AdminMajorQuestionMakeService {
|
24 | 24 |
|
25 |
| - private final QuestionRepository questionRepository; |
26 |
| - private final MajorMultipleChoiceQuestionRepository majorMultipleChoiceQuestionRepository; |
27 |
| - private final QuestionChoiceService questionChoiceService; |
28 |
| - private final DuplicateQuestionDetector duplicateQuestionDetector; |
| 25 | + private final QuestionRepository questionRepository; |
| 26 | + private final MajorMultipleChoiceQuestionRepository majorMultipleChoiceQuestionRepository; |
| 27 | + private final QuestionChoiceService questionChoiceService; |
| 28 | + private final DuplicateQuestionDetector duplicateQuestionDetector; |
29 | 29 |
|
30 |
| - /** |
31 |
| - * 리스트로 생성 |
32 |
| - */ |
33 |
| - @Override |
34 |
| - public List<MajorMultipleChoiceQuestion> makeMultipleChoiceQuestions( |
35 |
| - List<RequestMakeMultipleChoiceQuestionDto> requestDtos) { |
36 |
| - // 중복되지 않은 질문을 필터링하여 저장 |
37 |
| - return requestDtos.stream() |
38 |
| - .filter(this::isNotDuplicateQuestion) |
39 |
| - .map(this::saveMajorMultipleChoiceQuestion) |
40 |
| - .collect(Collectors.toList()); |
41 |
| - } |
| 30 | + /** |
| 31 | + * 리스트로 생성 |
| 32 | + */ |
| 33 | + @Override |
| 34 | + public List<MajorMultipleChoiceQuestion> makeMultipleChoiceQuestions( |
| 35 | + List<RequestMakeMultipleChoiceQuestionDto> requestDtos) { |
| 36 | + // 중복되지 않은 질문을 필터링하여 저장 |
| 37 | + return requestDtos.stream() |
| 38 | + .filter(this::isNotDuplicateQuestion) |
| 39 | + .map(this::saveMajorMultipleChoiceQuestion) |
| 40 | + .collect(Collectors.toList()); |
| 41 | + } |
42 | 42 |
|
43 |
| - /** |
44 |
| - * 단일 생성 |
45 |
| - */ |
46 |
| - @Override |
47 |
| - public MajorMultipleChoiceQuestion makeMultipleChoiceQuestion( |
48 |
| - RequestMakeMultipleChoiceQuestionDto requestDto) throws DuplicateQuestionContentException { |
49 |
| - if (!isNotDuplicateQuestion(requestDto)) { |
50 |
| - throw new DuplicateQuestionContentException(); |
51 |
| - } |
52 |
| - return saveMajorMultipleChoiceQuestion(requestDto); |
53 |
| - } |
| 43 | + /** |
| 44 | + * 단일 생성 |
| 45 | + */ |
| 46 | + @Override |
| 47 | + public MajorMultipleChoiceQuestion makeMultipleChoiceQuestion( |
| 48 | + RequestMakeMultipleChoiceQuestionDto requestDto) throws DuplicateQuestionContentException { |
| 49 | + if (!isNotDuplicateQuestion(requestDto)) { |
| 50 | + throw new DuplicateQuestionContentException(); |
| 51 | + } |
| 52 | + return saveMajorMultipleChoiceQuestion(requestDto); |
| 53 | + } |
54 | 54 |
|
55 |
| - @Override |
56 |
| - public List<MajorDescriptiveQuestion> makeDescriptiveQuestions( |
57 |
| - List<RequestMakeMajorDescriptiveQuestionDto> requestNormalQuestionDto) { |
| 55 | + @Override |
| 56 | + public List<MajorDescriptiveQuestion> makeDescriptiveQuestions( |
| 57 | + List<RequestMakeMajorDescriptiveQuestionDto> requestNormalQuestionDto) { |
58 | 58 |
|
59 |
| - return requestNormalQuestionDto.stream() |
60 |
| - .map(this::saveMajorDescriptiveQuestion) |
61 |
| - .collect(Collectors.toList()); |
62 |
| - } |
| 59 | + return requestNormalQuestionDto.stream() |
| 60 | + .map(this::saveMajorDescriptiveQuestion) |
| 61 | + .collect(Collectors.toList()); |
| 62 | + } |
63 | 63 |
|
64 |
| - /** |
65 |
| - * 중복되지 않은 질문인지 확인하는 메서드 |
66 |
| - * 매번 DB에서 새롭게 조회 후 검증한다.(DTO 자체의 중복된 데이터) |
67 |
| - */ |
68 |
| - private boolean isNotDuplicateQuestion(RequestMakeMultipleChoiceQuestionDto requestDto) { |
69 |
| - return majorMultipleChoiceQuestionRepository.findAll().stream() |
70 |
| - .noneMatch(existingQuestion -> duplicateQuestionDetector.isQuestionDuplicate( |
71 |
| - existingQuestion.getContent(), requestDto.getContent())); |
72 |
| - } |
| 64 | + /** |
| 65 | + * 중복되지 않은 질문인지 확인하는 메서드 |
| 66 | + * 매번 DB에서 새롭게 조회 후 검증한다.(DTO 자체의 중복된 데이터) |
| 67 | + */ |
| 68 | + private boolean isNotDuplicateQuestion(RequestMakeMultipleChoiceQuestionDto requestDto) { |
| 69 | + return majorMultipleChoiceQuestionRepository.findAll().stream() |
| 70 | + .noneMatch(existingQuestion -> duplicateQuestionDetector.isQuestionDuplicate( |
| 71 | + existingQuestion.getContent(), requestDto.getContent())); |
| 72 | + } |
73 | 73 |
|
74 |
| - /** |
75 |
| - * 새로운 질문을 저장하고 선택지를 저장하는 메서드 |
76 |
| - */ |
77 |
| - private MajorMultipleChoiceQuestion saveMajorMultipleChoiceQuestion( |
78 |
| - RequestMakeMultipleChoiceQuestionDto requestDto) { |
79 |
| - MajorMultipleChoiceQuestion question = MajorMultipleChoiceQuestion.makeWithDto(requestDto); |
80 |
| - questionRepository.save(question); |
81 |
| - questionChoiceService.saveWith(requestDto, question); |
82 |
| - return question; |
83 |
| - } |
| 74 | + /** |
| 75 | + * 새로운 질문을 저장하고 선택지를 저장하는 메서드 |
| 76 | + */ |
| 77 | + private MajorMultipleChoiceQuestion saveMajorMultipleChoiceQuestion( |
| 78 | + RequestMakeMultipleChoiceQuestionDto requestDto) { |
| 79 | + MajorMultipleChoiceQuestion question = MajorMultipleChoiceQuestion.makeWithDto(requestDto); |
| 80 | + questionRepository.save(question); |
| 81 | + questionChoiceService.saveWith(requestDto, question); |
| 82 | + return question; |
| 83 | + } |
84 | 84 |
|
85 |
| - private MajorDescriptiveQuestion saveMajorDescriptiveQuestion( |
86 |
| - RequestMakeMajorDescriptiveQuestionDto requestDto |
87 |
| - ) { |
88 |
| - MajorDescriptiveQuestion question = MajorDescriptiveQuestion.makeWithDto( |
89 |
| - requestDto |
90 |
| - ); |
91 |
| - questionRepository.save(question); |
92 |
| - return question; |
93 |
| - } |
| 85 | + private MajorDescriptiveQuestion saveMajorDescriptiveQuestion( |
| 86 | + RequestMakeMajorDescriptiveQuestionDto requestDto |
| 87 | + ) { |
| 88 | + MajorDescriptiveQuestion question = MajorDescriptiveQuestion.makeWithDto( |
| 89 | + requestDto |
| 90 | + ); |
| 91 | + questionRepository.save(question); |
| 92 | + return question; |
| 93 | + } |
94 | 94 | }
|
95 | 95 |
|
0 commit comments