Skip to content

Commit

Permalink
refactor: WalkRecordStatsService 로직 추가
Browse files Browse the repository at this point in the history
requestedDate가 없으면 오늘 날짜를 사용하는 로직을 서비스 계층으로 이동

related to : #38
  • Loading branch information
jieunjin committed Oct 13, 2024
1 parent 88f7d6b commit 8048618
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.time.LocalDate;
import java.time.YearMonth;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -24,9 +23,7 @@ public class WalkRecordStatsController {
public ResponseEntity<WalkStatsWithRecordsResponse> getWeeklyRecords(
@PathVariable("petId") Long petId,
@RequestParam(value = "date", required = false) LocalDate requestedDate) {
if (requestedDate == null) {
requestedDate = LocalDate.now();
}

WalkStatsWithRecordsResponse records = walkRecordStatsService.getWeeklyRecords(petId, requestedDate);
return ResponseEntity.ok(records);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class WalkRecordStatsService {

// 특정 반려동물의 주간 산책 기록을 조회하고 통계와 상세기록 응답
public WalkStatsWithRecordsResponse getWeeklyRecords(Long petId, LocalDate requestedDate) {
//요청된 날짜 없으면 오늘 날짜 사용
if (requestedDate == null) {
requestedDate = LocalDate.now();
}

// 현재 주의 시작일 (일요일)로 계산
LocalDate startOfWeek = requestedDate.with(WeekFields.of(Locale.KOREA).dayOfWeek(), 1);
LocalDate endOfWeek = startOfWeek.plusDays(6);
Expand Down

0 comments on commit 8048618

Please sign in to comment.