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

✨ 매칭된 돌봄 초기화 api 개발 #58

Merged
merged 14 commits into from
Dec 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ public ResponseEntity<?> getMatchedCare() {
return ResponseEntity.ok(response);
}


@PutMapping()
public ResponseEntity<?> init() {
Long currentMemberId = securityUtil.getCurrentMemberId();
CustomApiResponse<?> response = caregiverService.init(currentMemberId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public interface ApplyRepository extends JpaRepository<Apply, Long> {
Optional<Apply> findById (Long applyId);
Apply findFirstByChild_IdOrderByCreateAt(Long childID);
Optional<Apply> findFirstByStatusOrderByCreateAtDesc(Status status);
List<Apply> findAllByStatus(Status status);

}
17 changes: 17 additions & 0 deletions src/main/java/com/ivory/ivory/service/CaregiverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,21 @@ public CustomApiResponse<?> getMatchedCare(Long currentMemberId) {
CareDto careDto = CareDto.of(applyId,careDate,careTime,childName,age,image);
return CustomApiResponse.createSuccess(HttpStatus.OK.value(), "매칭된 돌봄 활동이 조회 되었습니다.",careDto);
}


public CustomApiResponse<?> init(Long currentMemberId) {
// Optional<Caregiver> caregiver = caregiverRepository.findById(currentMemberId);
// if (caregiver.isEmpty()) {
// throw new ResponseStatusException(HttpStatus.BAD_REQUEST,"돌보미만 초기화가 가능합니다.");
// }
//Status가 MATCHED인 것들을 모두 YET으로 바꿔주기
List<Apply> applies = applyRepository.findAllByStatus(Status.MATCHED);
applies.forEach((apply) -> {
apply.setStatus(Status.YET); //상태 변경
});

//상태 변경 내용 DB 저장
applyRepository.saveAll(applies);
return CustomApiResponse.createSuccess(HttpStatus.OK.value(),"상태가 초기화 되었습니다",null);
}
}