diff --git a/src/main/java/com/hsu/shimpyoo/domain/medicine/service/MedicineService.java b/src/main/java/com/hsu/shimpyoo/domain/medicine/service/MedicineService.java index b99b19e..8fa098c 100644 --- a/src/main/java/com/hsu/shimpyoo/domain/medicine/service/MedicineService.java +++ b/src/main/java/com/hsu/shimpyoo/domain/medicine/service/MedicineService.java @@ -4,6 +4,7 @@ import com.hsu.shimpyoo.domain.medicine.entity.MealTiming; import com.hsu.shimpyoo.domain.medicine.entity.Medicine; import com.hsu.shimpyoo.domain.medicine.repository.MedicineRepository; +import com.hsu.shimpyoo.domain.medicine.web.dto.MedicineTimeSettingDto; import com.hsu.shimpyoo.domain.user.entity.User; import com.hsu.shimpyoo.global.response.CustomAPIResponse; import lombok.RequiredArgsConstructor; @@ -58,6 +59,33 @@ private LocalTime calculateIntakeTime(LocalTime mealTime, MealTiming mealTiming, return mealTime.plusMinutes(adjustment); } + public ResponseEntity> getMedicineTimeSetting(User user) { + try { + // 해당 사용자의 약 복용 시간 정보 가져오기 + Medicine medicine = medicineRepository.findByUserId(user) + .orElseThrow(() -> new RuntimeException("약 복용 시간 설정이 존재하지 않습니다.")); + + MedicineTimeSettingDto data = MedicineTimeSettingDto.builder() + .breakfast(medicine.getBreakfast()) + .lunch(medicine.getLunch()) + .dinner(medicine.getDinner()) + .mealTiming(medicine.getMealTiming()) + .intakeTiming(medicine.getIntakeTiming()) + .build(); + + // 성공 응답 생성 + CustomAPIResponse response = CustomAPIResponse.createSuccess( + 200, data, "약 복용 시간 설정 정보가 성공적으로 조회되었습니다." + ); + return ResponseEntity.status(HttpStatus.OK).body(response); + + } catch (RuntimeException e) { + // 예외 처리 + CustomAPIResponse response = CustomAPIResponse.createFailWithout(404, e.getMessage()); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response); + } + } + public ResponseEntity> getMedicineTimeLeft(User user) { try { // 해당 사용자의 약 복용 시간 정보 가져오기 diff --git a/src/main/java/com/hsu/shimpyoo/domain/medicine/web/controller/MedicineController.java b/src/main/java/com/hsu/shimpyoo/domain/medicine/web/controller/MedicineController.java index 59049f6..fb57bc6 100644 --- a/src/main/java/com/hsu/shimpyoo/domain/medicine/web/controller/MedicineController.java +++ b/src/main/java/com/hsu/shimpyoo/domain/medicine/web/controller/MedicineController.java @@ -31,6 +31,15 @@ public ResponseEntity> setMedicineTime( return medicineService.MedicineTimeSetting(dto, user); } + @GetMapping("/getTimeSetting") + public ResponseEntity> getMedicineTimeSetting() { + String loginId = authenticationUserUtils.getCurrentUserId(); + User user = userRepository.findByLoginId(loginId) + .orElseThrow(() -> new UsernameNotFoundException("해당 사용자가 존재하지 않습니다.")); + + return medicineService.getMedicineTimeSetting(user); + } + @GetMapping("/getTimeLeft") public ResponseEntity> getMedicineTimeLeft() { String loginId = authenticationUserUtils.getCurrentUserId(); diff --git a/src/main/java/com/hsu/shimpyoo/domain/medicine/web/dto/MedicineTimeSettingDto.java b/src/main/java/com/hsu/shimpyoo/domain/medicine/web/dto/MedicineTimeSettingDto.java new file mode 100644 index 0000000..90b0c3e --- /dev/null +++ b/src/main/java/com/hsu/shimpyoo/domain/medicine/web/dto/MedicineTimeSettingDto.java @@ -0,0 +1,17 @@ +package com.hsu.shimpyoo.domain.medicine.web.dto; + +import com.hsu.shimpyoo.domain.medicine.entity.MealTiming; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalTime; + +@Getter +@Builder +public class MedicineTimeSettingDto { + private LocalTime breakfast; + private LocalTime lunch; + private LocalTime dinner; + private MealTiming mealTiming; + private Integer intakeTiming; +}