From 7110face01e2413e5da80da1429c7689f8754b15 Mon Sep 17 00:00:00 2001 From: oosedus Date: Wed, 4 Sep 2024 00:15:16 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=A4=91=EA=B0=84=EC=A0=84=ED=98=95?= =?UTF-8?q?=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/enums/ErrorCode.java | 1 + .../common/exception/enums/SuccessCode.java | 3 +- .../repository/MidReviewRepository.java | 2 ++ .../stage/controller/StageController.java | 13 +++++++ .../letscareer/stage/dto/ReviewDTO.java | 10 ++++++ .../dto/response/GetMidStageResponse.java | 9 +++++ .../stage/service/StageService.java | 35 +++++++++++++++++++ 7 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/example/letscareer/stage/dto/ReviewDTO.java create mode 100644 src/main/java/com/example/letscareer/stage/dto/response/GetMidStageResponse.java diff --git a/src/main/java/com/example/letscareer/common/exception/enums/ErrorCode.java b/src/main/java/com/example/letscareer/common/exception/enums/ErrorCode.java index be30233..8d08e6a 100644 --- a/src/main/java/com/example/letscareer/common/exception/enums/ErrorCode.java +++ b/src/main/java/com/example/letscareer/common/exception/enums/ErrorCode.java @@ -25,6 +25,7 @@ public enum ErrorCode { SCHEDULE_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 ID의 지원 일정을 찾을 수 없습니다."), STAGE_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 ID의 전형 단계를 찾을 수 없습니다."), DOC_STAGE_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 ID의 서류전형 단계를 찾을 수 없습니다."), + MID_STAGE_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 ID의 중간전형 단계를 찾을 수 없습니다."), // 405 METHOD_NOT_ALLOWED METHOD_NOT_ALLOWED_EXCEPTION(HttpStatus.METHOD_NOT_ALLOWED, "지원하지 않는 메소드 입니다."), diff --git a/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java b/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java index a6de88e..da544b5 100644 --- a/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java +++ b/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java @@ -29,7 +29,8 @@ public enum SuccessCode { STAGE_UPDATE_SUCCESS(HttpStatus.OK, "전형 단계 상태 변경 성공"), UPDATE_SCHEDULE_PROGRESS_SUCCESS(HttpStatus.OK, "일정 진행 상태 변경 성공"), STAGES_GET_SUCCESS(HttpStatus.OK, "지원 일정 및 단계 조회 성공"), - DOC_STAGES_GET_SUCCESS(HttpStatus.OK, "서류전형 단계 조회 성공"),; + DOC_STAGES_GET_SUCCESS(HttpStatus.OK, "서류전형 단계 조회 성공"), + MID_STAGES_GET_SUCCESS(HttpStatus.OK, "중간전형 단계 조회 성공"),; private final HttpStatus httpStatus; private final String message; diff --git a/src/main/java/com/example/letscareer/mid_review/repository/MidReviewRepository.java b/src/main/java/com/example/letscareer/mid_review/repository/MidReviewRepository.java index 3795194..d976e26 100644 --- a/src/main/java/com/example/letscareer/mid_review/repository/MidReviewRepository.java +++ b/src/main/java/com/example/letscareer/mid_review/repository/MidReviewRepository.java @@ -16,4 +16,6 @@ public interface MidReviewRepository extends JpaRepository { Optional findMidReviewIdByStageAndUser(Stage stage, User user); Optional findByMidReviewIdAndUser(Long midReviewId, User user); + + Optional findByStage(Stage stage); } diff --git a/src/main/java/com/example/letscareer/stage/controller/StageController.java b/src/main/java/com/example/letscareer/stage/controller/StageController.java index ecd29e8..3df13e3 100644 --- a/src/main/java/com/example/letscareer/stage/controller/StageController.java +++ b/src/main/java/com/example/letscareer/stage/controller/StageController.java @@ -75,4 +75,17 @@ public ApiResponse getDocumentStage( return ErrorResponse.error(e.getErrorCode()); } } + + @GetMapping("/schedules/{scheduleId}/stages/{stageId}/mid") + public ApiResponse getMidStage( + @RequestHeader("userId") Long userId, + @PathVariable Long scheduleId, + @PathVariable Long stageId + ) { + try { + return SuccessResponse.success(SuccessCode.MID_STAGES_GET_SUCCESS , stageService.getMidStage(userId, scheduleId, stageId)); + } catch (NotFoundException | BadRequestException e) { + return ErrorResponse.error(e.getErrorCode()); + } + } } diff --git a/src/main/java/com/example/letscareer/stage/dto/ReviewDTO.java b/src/main/java/com/example/letscareer/stage/dto/ReviewDTO.java new file mode 100644 index 0000000..b9f3aae --- /dev/null +++ b/src/main/java/com/example/letscareer/stage/dto/ReviewDTO.java @@ -0,0 +1,10 @@ +package com.example.letscareer.stage.dto; + +import java.time.LocalDate; + +public record ReviewDTO( + Long reviewId, + String free_review, + String goal +) { +} diff --git a/src/main/java/com/example/letscareer/stage/dto/response/GetMidStageResponse.java b/src/main/java/com/example/letscareer/stage/dto/response/GetMidStageResponse.java new file mode 100644 index 0000000..e5eb7a9 --- /dev/null +++ b/src/main/java/com/example/letscareer/stage/dto/response/GetMidStageResponse.java @@ -0,0 +1,9 @@ +package com.example.letscareer.stage.dto.response; + +import com.example.letscareer.stage.dto.ReviewDTO; + +public record GetMidStageResponse( + boolean reviewAvailable, + ReviewDTO review +) { +} diff --git a/src/main/java/com/example/letscareer/stage/service/StageService.java b/src/main/java/com/example/letscareer/stage/service/StageService.java index 19176e9..fcab2ad 100644 --- a/src/main/java/com/example/letscareer/stage/service/StageService.java +++ b/src/main/java/com/example/letscareer/stage/service/StageService.java @@ -3,6 +3,8 @@ import com.example.letscareer.appealCareer.domain.AppealCareer; import com.example.letscareer.appealCareer.repository.AppealCareerRepository; import com.example.letscareer.common.exception.model.NotFoundException; +import com.example.letscareer.mid_review.domain.MidReview; +import com.example.letscareer.mid_review.repository.MidReviewRepository; import com.example.letscareer.schedule.domain.Schedule; import com.example.letscareer.schedule.repository.ScheduleRepository; import com.example.letscareer.self_intro.domain.SelfIntro; @@ -12,11 +14,13 @@ import com.example.letscareer.stage.domain.Status; import com.example.letscareer.stage.domain.Type; import com.example.letscareer.stage.dto.AppealCareerDTO; +import com.example.letscareer.stage.dto.ReviewDTO; import com.example.letscareer.stage.dto.StageDTO; import com.example.letscareer.stage.dto.request.AddStageRequest; import com.example.letscareer.stage.dto.request.UpdateStageStatusRequest; import com.example.letscareer.stage.dto.response.AddStageResponse; import com.example.letscareer.stage.dto.response.GetDocumentStageResponse; +import com.example.letscareer.stage.dto.response.GetMidStageResponse; import com.example.letscareer.stage.dto.response.GetStagesResponse; import com.example.letscareer.stage.repository.StageRepository; import com.example.letscareer.user.domain.User; @@ -30,6 +34,7 @@ import java.time.Period; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import static com.example.letscareer.common.exception.enums.ErrorCode.*; @@ -43,6 +48,7 @@ public class StageService { private final UserRepository userRepository; private final SelfIntroRepository selfIntroRepository; private final AppealCareerRepository appealCareerRepository; + private final MidReviewRepository midReviewRepository; @Transactional public AddStageResponse addStage(Long userId, Long scheduleId, AddStageRequest request) { @@ -167,4 +173,33 @@ public GetDocumentStageResponse getDocumentStage(Long userId, Long scheduleId, L appealCareerDTOs ); } + + public GetMidStageResponse getMidStage(Long userId, Long scheduleId, Long stageId) { + 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.findByScheduleAndStageIdAndType(schedule, stageId, Type.MID) + .orElseThrow(() -> new NotFoundException(MID_STAGE_NOT_FOUND_EXCEPTION)); + + Optional midReview = midReviewRepository.findByStage(stage); + + if(midReview.isEmpty()) { + return new GetMidStageResponse( + true, + null + ); + } + else { + ReviewDTO reviewDTO = new ReviewDTO( + midReview.get().getMidReviewId(), + midReview.get().getFreeReview(), + midReview.get().getGoal() + ); + return new GetMidStageResponse( + false, + reviewDTO + ); + } + } }