diff --git a/src/main/java/com/ivory/ivory/controller/CaregiverController.java b/src/main/java/com/ivory/ivory/controller/CaregiverController.java index de7e60d..c887b46 100644 --- a/src/main/java/com/ivory/ivory/controller/CaregiverController.java +++ b/src/main/java/com/ivory/ivory/controller/CaregiverController.java @@ -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); + } } diff --git a/src/main/java/com/ivory/ivory/repository/ApplyRepository.java b/src/main/java/com/ivory/ivory/repository/ApplyRepository.java index 54f8338..1958a8d 100644 --- a/src/main/java/com/ivory/ivory/repository/ApplyRepository.java +++ b/src/main/java/com/ivory/ivory/repository/ApplyRepository.java @@ -14,5 +14,6 @@ public interface ApplyRepository extends JpaRepository { Optional findById (Long applyId); Apply findFirstByChild_IdOrderByCreateAt(Long childID); Optional findFirstByStatusOrderByCreateAtDesc(Status status); + List findAllByStatus(Status status); } diff --git a/src/main/java/com/ivory/ivory/service/CaregiverService.java b/src/main/java/com/ivory/ivory/service/CaregiverService.java index 6e715b7..ecc514d 100644 --- a/src/main/java/com/ivory/ivory/service/CaregiverService.java +++ b/src/main/java/com/ivory/ivory/service/CaregiverService.java @@ -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 = caregiverRepository.findById(currentMemberId); +// if (caregiver.isEmpty()) { +// throw new ResponseStatusException(HttpStatus.BAD_REQUEST,"돌보미만 초기화가 가능합니다."); +// } + //Status가 MATCHED인 것들을 모두 YET으로 바꿔주기 + List applies = applyRepository.findAllByStatus(Status.MATCHED); + applies.forEach((apply) -> { + apply.setStatus(Status.YET); //상태 변경 + }); + + //상태 변경 내용 DB 저장 + applyRepository.saveAll(applies); + return CustomApiResponse.createSuccess(HttpStatus.OK.value(),"상태가 초기화 되었습니다",null); + } }