diff --git a/src/main/java/com/example/sinitto/guardGuideline/controller/GuardGuidelineController.java b/src/main/java/com/example/sinitto/guardGuideline/controller/GuardGuidelineController.java index 02f372d7..6976a65b 100644 --- a/src/main/java/com/example/sinitto/guardGuideline/controller/GuardGuidelineController.java +++ b/src/main/java/com/example/sinitto/guardGuideline/controller/GuardGuidelineController.java @@ -14,7 +14,7 @@ @RestController @RequestMapping("/api/guardguidelines") -@Tag(name = "보호자용 가이드라인", description = "보호자가 입력하는 시니어별 가이드라인 관련 API") +@Tag(name = "가이드라인", description = "가이드라인 관련 API") public class GuardGuidelineController { private final GuardGuidelineService guardGuidelineService; @@ -30,10 +30,16 @@ public ResponseEntity addGuardGuideline(@MemberId Long memberId, @Reques return ResponseEntity.ok("가이드라인이 추가되었습니다."); } - @Operation(summary = "카테고리에 해당하는 모든 가이드라인 조회", description = "시니또용 앱에서 카테고리에 해당하는 모든 가이드라인들을 요청할 때 필요합니다.") - @GetMapping("/{seniorId}/{type}") - public ResponseEntity> getGuardGuidelinesByCategory(@PathVariable Long seniorId, @PathVariable GuardGuideline.Type type) { - return ResponseEntity.ok(guardGuidelineService.readAllGuardGuidelinesByCategory(seniorId, type)); + @Operation(summary = "카테고리에 해당하는 모든 가이드라인 조회(보호자용)", description = "보호자용 앱에서 카테고리에 해당하는 모든 가이드라인들을 요청할 때 필요합니다.") + @GetMapping("/guard/{seniorId}/{type}") + public ResponseEntity> getGuardGuidelinesByCategoryAndSenior(@MemberId Long memberId, @PathVariable Long seniorId, @PathVariable GuardGuideline.Type type) { + return ResponseEntity.ok(guardGuidelineService.readAllGuardGuidelinesByCategoryAndSenior(memberId, seniorId, type)); + } + + @Operation(summary = "카테고리에 해당하는 모든 가이드라인 조회(시니또용)", description = "시니또용 앱에서 카테고리에 해당하는 모든 가이드라인들을 요청할 때 필요합니다.") + @GetMapping("/sinitto/{callbackId}/{type}") + public ResponseEntity> getGuardGuidelinesByCategoryAndCallback(@MemberId Long memberId, @PathVariable Long callbackId, @PathVariable GuardGuideline.Type type) { + return ResponseEntity.ok(guardGuidelineService.readAllGuardGuidelinesByCategoryAndCallback(memberId, callbackId, type)); } @Operation(summary = "가이드라인 수정", description = "보호자가 특정 가이드라인을 수정할 때 필요합니다.") @@ -50,11 +56,6 @@ public ResponseEntity> getAllGuardGuidelinesBySenio return ResponseEntity.ok(guardGuidelineService.readAllGuardGuidelinesBySenior(memberId, seniorId)); } - @Operation(summary = "특정 가이드라인 조회", description = "보호자용 API입니다.") - @GetMapping("/detail") - public ResponseEntity getGuardGuideline(@RequestParam("callbackId") Long callbackId, @RequestParam("guidelineId") Long guidelineId) { - return ResponseEntity.ok(guardGuidelineService.readGuardGuideline(callbackId, guidelineId)); - } @Operation(summary = "특정 가이드라인 삭제", description = "보호자용 API입니다.") @DeleteMapping("/delete") diff --git a/src/main/java/com/example/sinitto/guardGuideline/service/GuardGuidelineService.java b/src/main/java/com/example/sinitto/guardGuideline/service/GuardGuidelineService.java index 8558982a..69e9be77 100644 --- a/src/main/java/com/example/sinitto/guardGuideline/service/GuardGuidelineService.java +++ b/src/main/java/com/example/sinitto/guardGuideline/service/GuardGuidelineService.java @@ -43,7 +43,28 @@ public void addGuardGuideline(Long memberId, GuardGuidelineRequest guardGuidelin } @Transactional(readOnly = true) - public List readAllGuardGuidelinesByCategory(Long seniorId, Type type) { + public List readAllGuardGuidelinesByCategoryAndSenior(Long memberId, Long seniorId, Type type) { + List guardGuidelines = guardGuidelineRepository.findBySeniorIdAndType(seniorId, type); + Senior senior = seniorRepository.findById(seniorId).orElseThrow( + () -> new NotFoundException("시니어를 찾을 수 없습니다.") + ); + if (senior.isNotGuard(memberId)) { + throw new BadRequestException("해당 Guard의 Senior가 아닙니다."); + } + return guardGuidelines.stream() + .map(m -> new GuardGuidelineResponse(m.getId(), m.getType(), m.getTitle(), m.getContent())) + .toList(); + } + + @Transactional(readOnly = true) + public List readAllGuardGuidelinesByCategoryAndCallback(Long memberId, Long callbackId, Type type) { + Callback callback = callbackRepository.findById(callbackId) + .orElseThrow(() -> new NotFoundException("존재하지 않는 콜백입니다")); + + if (callback.getStatus() != Callback.Status.WAITING.name() && callback.getAssignedMemberId() != memberId) { + throw new BadRequestException("해당 콜백은 대기 상태가 아니고, 배정 시니또가 아닙니다."); + } + Long seniorId = callback.getSeniorId(); List guardGuidelines = guardGuidelineRepository.findBySeniorIdAndType(seniorId, type); return guardGuidelines.stream() @@ -92,21 +113,4 @@ public List readAllGuardGuidelinesBySenior(Long memberId .map(m -> new GuardGuidelineResponse(m.getId(), m.getType(), m.getTitle(), m.getContent())) .toList(); } - - @Transactional(readOnly = true) - public GuardGuidelineResponse readGuardGuideline(Long callbackId, Long guidelineId) { - - Callback callback = callbackRepository.findById(callbackId) - .orElseThrow(() -> new NotFoundException("존재하지 않는 콜백입니다")); - - GuardGuideline guardGuideline = guardGuidelineRepository.findById(guidelineId).orElseThrow( - () -> new NotFoundException("해당 가이드라인이 존재하지 않습니다.") - ); - - if (!callback.getSenior().equals(guardGuideline.getSenior())) { - throw new BadRequestException("해당 Senior의 가이드라인이 아닙니다."); - } - - return new GuardGuidelineResponse(guardGuideline.getId(), guardGuideline.getType(), guardGuideline.getTitle(), guardGuideline.getContent()); - } }