Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ FEAT. 약 복용 시간 조회 #68

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading