|
3 | 3 | import Devroup.hidaddy.dto.weeklycontent.WeeklyContentResponse; |
4 | 4 | import Devroup.hidaddy.dto.weeklycontent.WeeklyContentSimpleResponse; |
5 | 5 | import Devroup.hidaddy.entity.Baby; |
| 6 | +import Devroup.hidaddy.entity.BabyGroup; |
6 | 7 | import Devroup.hidaddy.entity.WeeklyContent; |
| 8 | +import Devroup.hidaddy.repository.user.BabyGroupRepository; |
7 | 9 | import Devroup.hidaddy.repository.user.BabyRepository; |
8 | 10 | import Devroup.hidaddy.repository.weeklycontent.WeeklyContentRepository; |
9 | 11 | import lombok.RequiredArgsConstructor; |
|
12 | 14 |
|
13 | 15 | import java.time.LocalDate; |
14 | 16 | import java.time.temporal.ChronoUnit; |
| 17 | +import java.util.List; |
15 | 18 |
|
16 | 19 | @Service |
17 | 20 | @RequiredArgsConstructor |
18 | 21 | @Transactional(readOnly = true) |
19 | 22 | public class WeeklyContentService { |
20 | | - private final BabyRepository babyRepository; |
| 23 | + private final BabyGroupRepository babyGroupRepository; |
21 | 24 | private final WeeklyContentRepository weeklyContentRepository; |
22 | 25 |
|
23 | 26 | // 출산 예정일로부터 현재 날짜 계산하여 해당 주차 컨텐츠 출력 |
24 | | - public WeeklyContentResponse getWeeklyContent(Long babyId) { |
25 | | - Baby baby = babyRepository.findById(babyId) |
26 | | - .orElseThrow(() -> new IllegalArgumentException("아이를 찾을 수 없습니다.")); |
| 27 | + public WeeklyContentResponse getWeeklyContent(Long groupId) { |
| 28 | + BabyGroup group = babyGroupRepository.findWithBabiesById(groupId) |
| 29 | + .orElseThrow(() -> new IllegalArgumentException("선택된 아기 그룹을 찾을 수 없습니다.")); |
27 | 30 |
|
28 | | - int currentweek = caculateCurrentWeek(baby.getDueDate().toLocalDate()); |
| 31 | + List<Baby> babies = group.getBabies(); |
| 32 | + |
| 33 | + int currentweek = caculateCurrentWeek(babies.get(0).getDueDate().toLocalDate()); |
29 | 34 |
|
30 | 35 | WeeklyContent weeklyContent = weeklyContentRepository.findByWeek(currentweek) |
31 | 36 | .orElseThrow(() -> new IllegalArgumentException(currentweek + "주차 데이터가 없습니다.")); |
|
0 commit comments