이번 포스팅에서는 오늘의 약 알림을 조회하는 api를 구현해보도록 하겠다
MedicationService에 다음과 같이 메서드를 작성한다
public List<MedicationDTO> getTodayMedicationList(
Long memberId
) {
Member member = memberRepo.findById(memberId)
.orElseThrow(() -> new InvalidIdException(memberId, "member"));
// TODO: 현재 로그인한 유저와 memberId에 해당하는 유저가 같은 family_id를 가지고 있는지 확인
String dayOfTheWeek = String.valueOf(LocalDate.now().getDayOfWeek().getValue());
return medicationRepo.findAllByMemberId(memberId)
.stream()
.filter(e -> { return e.getDayOfTheWeekList().contains(dayOfTheWeek); })
.map(e -> MedicationDTO.entityToDto(e))
.collect(Collectors.toList());
}
MedicationController에 다음과 같이 메서드를 작성한다
@GetMapping("/api/medication/getTodayMedicationList")
public List<MedicationDTO> getTodayMedicationList(
@RequestParam Long memberId
){
return medicationService.getTodayMedicationList(memberId);
}
데이터베이스에 다음과 같이 medication 데이터가 저장되어있다
위와 같이 request를 보내면 아래와 같이 금요일에만 해당하는 medication이 반환되는 것을 확인할 수 있다
(포스팅을 작성하는 오늘은 금요일이다..!)
[WithParents] SpringSecurity 적용하기 (0) | 2023.01.13 |
---|---|
[WithParents] RDS 생성 후 스프링부트에 연동 | ec2 인스턴스 생성 (0) | 2023.01.13 |
[WithParents] 약알림 조회 기능 구현, getMedicationList api 구현 (1) | 2022.12.02 |
[WithParents] 약알림 삭제 기능 구현, deleteMedication api 구현 (0) | 2022.12.02 |
[WithParents] 약알림 수정 기능 구현, modifyMedication api 구현 (0) | 2022.12.02 |