diff --git a/src/main/java/com/hsu/shimpyoo/domain/breathing/service/BreathingCheckServiceImpl.java b/src/main/java/com/hsu/shimpyoo/domain/breathing/service/BreathingCheckServiceImpl.java index 9b06743..6010b6f 100644 --- a/src/main/java/com/hsu/shimpyoo/domain/breathing/service/BreathingCheckServiceImpl.java +++ b/src/main/java/com/hsu/shimpyoo/domain/breathing/service/BreathingCheckServiceImpl.java @@ -12,14 +12,12 @@ import com.hsu.shimpyoo.domain.user.entity.User; import com.hsu.shimpyoo.domain.user.repository.UserRepository; import com.hsu.shimpyoo.global.aws.s3.service.S3Service; -import com.hsu.shimpyoo.global.response.CustomAPIResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.ErrorResponseException; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.server.ResponseStatusException; diff --git a/src/main/java/com/hsu/shimpyoo/domain/breathing/service/BreathingService.java b/src/main/java/com/hsu/shimpyoo/domain/breathing/service/BreathingService.java index 7f98c1c..beb3935 100644 --- a/src/main/java/com/hsu/shimpyoo/domain/breathing/service/BreathingService.java +++ b/src/main/java/com/hsu/shimpyoo/domain/breathing/service/BreathingService.java @@ -75,14 +75,22 @@ public CustomAPIResponse> calculateBreathingResult(Breathing // 현재 요일에 해당하는 WeekDay Enum을 가져옵니다. WeekDay currentWeekDay = WeekDay.valueOf(LocalDateTime.now().getDayOfWeek().name()); - // DailyPef 데이터베이스에 상태와 최대호기량을 저장 - DailyPef dailyPef = DailyPef.builder() - .userId(user) - .pef(maxBreathingRate) - .state(state) // Enum 타입으로 상태 저장 - .weekDay(currentWeekDay) // Enum 타입으로 요일 저장 - .build(); - dailyPefRepository.save(dailyPef); + LocalDateTime startOfToday = LocalDate.now().atStartOfDay(); // 오늘의 시작 시간 + LocalDateTime endOfToday = LocalDate.now().atTime(LocalTime.MAX); // 오늘의 끝 시간 + + // 이미 오늘의 DailyPef 데이터가 저장되어 있는지 확인 + Optional existingDailyPef = dailyPefRepository.findTopByUserIdAndCreatedAtBetweenOrderByCreatedAtDesc(user, startOfToday, endOfToday); + + // 오늘의 데이터가 없을 때만 저장 + if (!existingDailyPef.isPresent()) { // DailyPef 데이터베이스에 상태와 최대호기량을 저장 + DailyPef dailyPef = DailyPef.builder() + .userId(user) + .pef(maxBreathingRate) + .state(state) // Enum 타입으로 상태 저장 + .weekDay(currentWeekDay) // Enum 타입으로 요일 저장 + .build(); + dailyPefRepository.save(dailyPef); + } // 반환 데이터 Map responseData = new LinkedHashMap<>(); diff --git a/src/main/java/com/hsu/shimpyoo/domain/breathing/web/controller/BreathingController.java b/src/main/java/com/hsu/shimpyoo/domain/breathing/web/controller/BreathingController.java index fe91b83..6dc874a 100644 --- a/src/main/java/com/hsu/shimpyoo/domain/breathing/web/controller/BreathingController.java +++ b/src/main/java/com/hsu/shimpyoo/domain/breathing/web/controller/BreathingController.java @@ -29,18 +29,6 @@ public class BreathingController { private final UserRepository userRepository; private final BreathingRepository breathingRepository; -// // 오늘의 쉼 결과 -// @PostMapping("/today/result") -// public CustomAPIResponse> getTodayBreathingResult( -// @RequestBody BreathingPefDto dto) { -// // 현재 로그인된 사용자 정보 가져오기 -// String loginId = authenticationUserUtils.getCurrentUserId(); -// User user = userRepository.findByLoginId(loginId) -// .orElseThrow(() -> new UsernameNotFoundException("해당 사용자가 존재하지 않습니다.")); -// -// return breathingService.calculateBreathingResult(dto, user); -// } - // 오늘 측정한 호흡 기록을 찾아서, 결과를 조회 @GetMapping("/today/result") public CustomAPIResponse> getTodayBreathingResult() {