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

Feat: 시니또용 카테고리별 가이드라인 조회 api 추가 및 기존 api 삭제 (프론트 요청) #114

Merged
merged 8 commits into from
Oct 28, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@RestController
@RequestMapping("/api/guardguidelines")
@Tag(name = "보호자용 가이드라인", description = "보호자가 입력하는 시니어별 가이드라인 관련 API")
@Tag(name = "가이드라인", description = "가이드라인 관련 API")
public class GuardGuidelineController {

private final GuardGuidelineService guardGuidelineService;
Expand All @@ -30,10 +30,16 @@ public ResponseEntity<String> addGuardGuideline(@MemberId Long memberId, @Reques
return ResponseEntity.ok("가이드라인이 추가되었습니다.");
}

@Operation(summary = "카테고리에 해당하는 모든 가이드라인 조회", description = "시니또용 앱에서 카테고리에 해당하는 모든 가이드라인들을 요청할 때 필요합니다.")
@GetMapping("/{seniorId}/{type}")
public ResponseEntity<List<GuardGuidelineResponse>> getGuardGuidelinesByCategory(@PathVariable Long seniorId, @PathVariable GuardGuideline.Type type) {
return ResponseEntity.ok(guardGuidelineService.readAllGuardGuidelinesByCategory(seniorId, type));
@Operation(summary = "카테고리에 해당하는 모든 가이드라인 조회(보호자용)", description = "보호자용 앱에서 카테고리에 해당하는 모든 가이드라인들을 요청할 때 필요합니다.")
@GetMapping("/guard/{seniorId}/{type}")
public ResponseEntity<List<GuardGuidelineResponse>> getGuardGuidelinesByCategoryAndSenior(@MemberId Long memberId, @PathVariable Long seniorId, @PathVariable GuardGuideline.Type type) {
return ResponseEntity.ok(guardGuidelineService.readAllGuardGuidelinesByCategoryAndSenior(memberId, seniorId, type));
}

@Operation(summary = "카테고리에 해당하는 모든 가이드라인 조회(시니또용)", description = "시니또용 앱에서 카테고리에 해당하는 모든 가이드라인들을 요청할 때 필요합니다.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분이 콜백 요청 수락하기 전에 확인하는 가이드라인 정보 제공하는 용도인거죠?? 헷갈려가지구 남깁니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 콜백 수락하기 전에 시니또가 가이드라인 확인하는 용도입니다!

@GetMapping("/sinitto/{callbackId}/{type}")
public ResponseEntity<List<GuardGuidelineResponse>> getGuardGuidelinesByCategoryAndCallback(@MemberId Long memberId, @PathVariable Long callbackId, @PathVariable GuardGuideline.Type type) {
return ResponseEntity.ok(guardGuidelineService.readAllGuardGuidelinesByCategoryAndCallback(memberId, callbackId, type));
}

@Operation(summary = "가이드라인 수정", description = "보호자가 특정 가이드라인을 수정할 때 필요합니다.")
Expand All @@ -50,11 +56,6 @@ public ResponseEntity<List<GuardGuidelineResponse>> getAllGuardGuidelinesBySenio
return ResponseEntity.ok(guardGuidelineService.readAllGuardGuidelinesBySenior(memberId, seniorId));
}

@Operation(summary = "특정 가이드라인 조회", description = "보호자용 API입니다.")
@GetMapping("/detail")
public ResponseEntity<GuardGuidelineResponse> getGuardGuideline(@RequestParam("callbackId") Long callbackId, @RequestParam("guidelineId") Long guidelineId) {
return ResponseEntity.ok(guardGuidelineService.readGuardGuideline(callbackId, guidelineId));
}

@Operation(summary = "특정 가이드라인 삭제", description = "보호자용 API입니다.")
@DeleteMapping("/delete")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,28 @@ public void addGuardGuideline(Long memberId, GuardGuidelineRequest guardGuidelin
}

@Transactional(readOnly = true)
public List<GuardGuidelineResponse> readAllGuardGuidelinesByCategory(Long seniorId, Type type) {
public List<GuardGuidelineResponse> readAllGuardGuidelinesByCategoryAndSenior(Long memberId, Long seniorId, Type type) {
List<GuardGuideline> 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<GuardGuidelineResponse> 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<GuardGuideline> guardGuidelines = guardGuidelineRepository.findBySeniorIdAndType(seniorId, type);

return guardGuidelines.stream()
Expand Down Expand Up @@ -92,21 +113,4 @@ public List<GuardGuidelineResponse> 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());
}
}