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