Skip to content

Commit

Permalink
Merge pull request #68 from shim-pyoo/feat/#67-getTimeSetting
Browse files Browse the repository at this point in the history
✨ FEAT. 약 복용 시간 조회
  • Loading branch information
eunxn authored Sep 8, 2024
2 parents 134edfa + 5f8a90a commit 973bccd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +59,33 @@ private LocalTime calculateIntakeTime(LocalTime mealTime, MealTiming mealTiming,
return mealTime.plusMinutes(adjustment);
}

public ResponseEntity<CustomAPIResponse<?>> 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<MedicineTimeSettingDto> response = CustomAPIResponse.createSuccess(
200, data, "약 복용 시간 설정 정보가 성공적으로 조회되었습니다."
);
return ResponseEntity.status(HttpStatus.OK).body(response);

} catch (RuntimeException e) {
// 예외 처리
CustomAPIResponse<String> response = CustomAPIResponse.createFailWithout(404, e.getMessage());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
}

public ResponseEntity<CustomAPIResponse<?>> getMedicineTimeLeft(User user) {
try {
// 해당 사용자의 약 복용 시간 정보 가져오기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public ResponseEntity<CustomAPIResponse<?>> setMedicineTime(
return medicineService.MedicineTimeSetting(dto, user);
}

@GetMapping("/getTimeSetting")
public ResponseEntity<CustomAPIResponse<?>> getMedicineTimeSetting() {
String loginId = authenticationUserUtils.getCurrentUserId();
User user = userRepository.findByLoginId(loginId)
.orElseThrow(() -> new UsernameNotFoundException("해당 사용자가 존재하지 않습니다."));

return medicineService.getMedicineTimeSetting(user);
}

@GetMapping("/getTimeLeft")
public ResponseEntity<CustomAPIResponse<?>> getMedicineTimeLeft() {
String loginId = authenticationUserUtils.getCurrentUserId();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 973bccd

Please sign in to comment.