|
1 |
| -package ddangkong.service.question; |
| 1 | +package ddangkong.service.content; |
2 | 2 |
|
3 |
| -import ddangkong.controller.question.dto.BalanceQuestionResponse; |
| 3 | +import ddangkong.controller.content.dto.BalanceContentResponse; |
4 | 4 | import ddangkong.domain.option.BalanceOption;
|
5 | 5 | import ddangkong.domain.option.BalanceOptionRepository;
|
6 |
| -import ddangkong.domain.question.BalanceQuestion; |
7 |
| -import ddangkong.domain.question.RoomQuestionRepository; |
| 6 | +import ddangkong.domain.content.BalanceContent; |
| 7 | +import ddangkong.domain.content.RoomContentRepository; |
8 | 8 | import ddangkong.service.excpetion.BusinessLogicException;
|
9 | 9 | import ddangkong.service.excpetion.ViolateDataException;
|
10 | 10 | import java.util.List;
|
|
14 | 14 |
|
15 | 15 | @Service
|
16 | 16 | @RequiredArgsConstructor
|
17 |
| -public class BalanceQuestionService { |
| 17 | +public class BalanceContentService { |
18 | 18 |
|
19 | 19 | private static final int BALANCE_OPTION_SIZE = 2;
|
20 | 20 |
|
21 |
| - private final RoomQuestionRepository roomQuestionRepository; |
| 21 | + private final RoomContentRepository roomContentRepository; |
22 | 22 |
|
23 | 23 | private final BalanceOptionRepository balanceOptionRepository;
|
24 | 24 |
|
25 | 25 | @Transactional(readOnly = true)
|
26 |
| - public BalanceQuestionResponse findRecentBalanceQuestion(Long roomId) { |
27 |
| - BalanceQuestion balanceQuestion = findRecentQuestion(roomId); |
28 |
| - List<BalanceOption> balanceOptions = findBalanceOptions(balanceQuestion); |
| 26 | + public BalanceContentResponse findRecentBalanceContent(Long roomId) { |
| 27 | + BalanceContent balanceContent = findRecentContent(roomId); |
| 28 | + List<BalanceOption> balanceOptions = findBalanceOptions(balanceContent); |
29 | 29 |
|
30 |
| - return BalanceQuestionResponse.builder() |
31 |
| - .question(balanceQuestion) |
| 30 | + return BalanceContentResponse.builder() |
| 31 | + .balanceContent(balanceContent) |
32 | 32 | .firstOption(balanceOptions.get(0))
|
33 | 33 | .secondOption(balanceOptions.get(1))
|
34 | 34 | .build();
|
35 | 35 | }
|
36 | 36 |
|
37 |
| - private BalanceQuestion findRecentQuestion(Long roomId) { |
38 |
| - return roomQuestionRepository.findTopByRoomIdOrderByCreatedAtDesc(roomId) |
| 37 | + private BalanceContent findRecentContent(Long roomId) { |
| 38 | + return roomContentRepository.findTopByRoomIdOrderByCreatedAtDesc(roomId) |
39 | 39 | .orElseThrow(() -> new BusinessLogicException("해당 방의 질문이 존재하지 않습니다."))
|
40 |
| - .getBalanceQuestion(); |
| 40 | + .getBalanceContent(); |
41 | 41 | }
|
42 | 42 |
|
43 |
| - private List<BalanceOption> findBalanceOptions(BalanceQuestion balanceQuestion) { |
44 |
| - List<BalanceOption> balanceOptions = balanceOptionRepository.findByBalanceQuestion(balanceQuestion); |
| 43 | + private List<BalanceOption> findBalanceOptions(BalanceContent balanceContent) { |
| 44 | + List<BalanceOption> balanceOptions = balanceOptionRepository.findByBalanceContent(balanceContent); |
45 | 45 | validateBalanceOptions(balanceOptions);
|
46 | 46 | return balanceOptions;
|
47 | 47 | }
|
|
0 commit comments