Skip to content

Commit f7b683f

Browse files
authored
Merge pull request #53 from Devroup/feature/weeklyContent-parameter-modify
feat: getWeeklyContent parameter를 babyId에서 babyGroupId로 수정
2 parents 331eeae + c669b6b commit f7b683f

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/main/java/Devroup/hidaddy/controller/WeeklyContent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public class WeeklyContent {
2222
@Operation(summary = "현재 주차의 정보 조회", description = "아이의 출산 예정일로 현재 주차를 계산하고 정보를 조회합니다.")
2323
@GetMapping("/current")
2424
public ResponseEntity<WeeklyContentResponse> getCurrentWeeklyContent(
25-
@RequestParam Long babyId,
25+
@RequestParam Long groupId,
2626
@AuthenticationPrincipal User user
2727
) {
28-
return ResponseEntity.ok(weeklyContentService.getWeeklyContent(babyId));
28+
return ResponseEntity.ok(weeklyContentService.getWeeklyContent(groupId));
2929
}
3030

3131
@Operation(summary = "특정 주차의 정보 조회", description = "원하는 특정 주차의 정보를 조회합니다.")

src/main/java/Devroup/hidaddy/service/WeeklyContentService.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import Devroup.hidaddy.dto.weeklycontent.WeeklyContentResponse;
44
import Devroup.hidaddy.dto.weeklycontent.WeeklyContentSimpleResponse;
55
import Devroup.hidaddy.entity.Baby;
6+
import Devroup.hidaddy.entity.BabyGroup;
67
import Devroup.hidaddy.entity.WeeklyContent;
8+
import Devroup.hidaddy.repository.user.BabyGroupRepository;
79
import Devroup.hidaddy.repository.user.BabyRepository;
810
import Devroup.hidaddy.repository.weeklycontent.WeeklyContentRepository;
911
import lombok.RequiredArgsConstructor;
@@ -12,20 +14,23 @@
1214

1315
import java.time.LocalDate;
1416
import java.time.temporal.ChronoUnit;
17+
import java.util.List;
1518

1619
@Service
1720
@RequiredArgsConstructor
1821
@Transactional(readOnly = true)
1922
public class WeeklyContentService {
20-
private final BabyRepository babyRepository;
23+
private final BabyGroupRepository babyGroupRepository;
2124
private final WeeklyContentRepository weeklyContentRepository;
2225

2326
// 출산 예정일로부터 현재 날짜 계산하여 해당 주차 컨텐츠 출력
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("선택된 아기 그룹을 찾을 수 없습니다."));
2730

28-
int currentweek = caculateCurrentWeek(baby.getDueDate().toLocalDate());
31+
List<Baby> babies = group.getBabies();
32+
33+
int currentweek = caculateCurrentWeek(babies.get(0).getDueDate().toLocalDate());
2934

3035
WeeklyContent weeklyContent = weeklyContentRepository.findByWeek(currentweek)
3136
.orElseThrow(() -> new IllegalArgumentException(currentweek + "주차 데이터가 없습니다."));

0 commit comments

Comments
 (0)