From 5207f98559cddb5fa7e632b3d0cac161bcd41cc3 Mon Sep 17 00:00:00 2001 From: oosedus Date: Sun, 1 Sep 2024 23:38:22 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20=ED=95=B4=EB=8B=B9=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=9D=98=20=EC=8A=A4=EC=BC=80=EC=A5=B4=EC=9D=B8=EC=A7=80,=20?= =?UTF-8?q?=ED=95=B4=EB=8B=B9=20=EC=8A=A4=EC=BC=80=EC=A5=B4=EC=9D=98=20?= =?UTF-8?q?=EB=8B=A8=EA=B3=84=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../letscareer/int_review/service/IntReviewService.java | 8 ++++---- .../letscareer/mid_review/service/MidReviewService.java | 8 ++++---- .../schedule/repository/ScheduleRepository.java | 5 +++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/example/letscareer/int_review/service/IntReviewService.java b/src/main/java/com/example/letscareer/int_review/service/IntReviewService.java index 56efb69..cca7263 100644 --- a/src/main/java/com/example/letscareer/int_review/service/IntReviewService.java +++ b/src/main/java/com/example/letscareer/int_review/service/IntReviewService.java @@ -30,12 +30,12 @@ public class IntReviewService { @Transactional public void postIntReview(Long userId, Long scheduleId, Long stageId, PostIntReviewRequest request) { - Schedule schedule = scheduleRepository.findById(scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - Stage stage = stageRepository.findById(stageId) - .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); User user = userRepository.findById(userId) .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); + Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) + .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); + Stage stage = stageRepository.findByStageIdAndSchedule(stageId, schedule) + .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); IntReview intReview = IntReview.builder() .stage(stage) diff --git a/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java b/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java index 7725ff5..75ae3de 100644 --- a/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java +++ b/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java @@ -45,12 +45,12 @@ public class MidReviewService { @Transactional public void postMidReview(Long userId, Long scheduleId, Long stageId, PostMidReviewRequest request) { - Schedule schedule = scheduleRepository.findById(scheduleId) - .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); - Stage stage = stageRepository.findById(stageId) - .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); User user = userRepository.findById(userId) .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); + Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) + .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); + Stage stage = stageRepository.findByStageIdAndSchedule(stageId, schedule) + .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); MidReview midReview = MidReview.builder() .freeReview(request.free_review()) diff --git a/src/main/java/com/example/letscareer/schedule/repository/ScheduleRepository.java b/src/main/java/com/example/letscareer/schedule/repository/ScheduleRepository.java index 529cd5b..4581198 100644 --- a/src/main/java/com/example/letscareer/schedule/repository/ScheduleRepository.java +++ b/src/main/java/com/example/letscareer/schedule/repository/ScheduleRepository.java @@ -1,6 +1,7 @@ package com.example.letscareer.schedule.repository; import com.example.letscareer.schedule.domain.Schedule; +import com.example.letscareer.user.domain.User; import io.lettuce.core.dynamic.annotation.Param; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -8,7 +9,11 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface ScheduleRepository extends JpaRepository { Page findAllByUserUserIdAndAlwaysTrue(Long userId, Pageable pageable); + + Optional findByUserAndScheduleId(User user, Long scheduleId); }