From 2b6383142fc69f1b60cf03e86aab4da31a4c38c1 Mon Sep 17 00:00:00 2001 From: pkl0912 Date: Mon, 2 Sep 2024 20:06:45 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#43=20[feat]=20=EC=A4=91=EA=B0=84=ED=9A=8C?= =?UTF-8?q?=EA=B3=A0=20service=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/enums/ErrorCode.java | 2 +- .../dto/response/MidReviewDetailResponse.java | 18 +++++++++++++++++ .../repository/MidReviewRepository.java | 2 ++ .../mid_review/service/MidReviewService.java | 20 +++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/example/letscareer/mid_review/dto/response/MidReviewDetailResponse.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 494fa6b..07905f3 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 @@ -18,7 +18,7 @@ public enum ErrorCode { //404 NOT_FOUND_RESOURCE_EXCEPTION(HttpStatus.NOT_FOUND, "해당 자원을 찾을 수 없습니다."), USER_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 유저는 존재하지 않습니다."), - KEYWORD_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 키워드는 존재하지 않습니다."), + MID_REVIEW_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 중간회고는 존재하지 않습니다."), CAREER_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 커리어는 존재하지 않습니다."), TODO_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 투두는 존재하지 않습니다"), SCHEDULE_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 ID의 지원 일정을 찾을 수 없습니다."), diff --git a/src/main/java/com/example/letscareer/mid_review/dto/response/MidReviewDetailResponse.java b/src/main/java/com/example/letscareer/mid_review/dto/response/MidReviewDetailResponse.java new file mode 100644 index 0000000..89ec1db --- /dev/null +++ b/src/main/java/com/example/letscareer/mid_review/dto/response/MidReviewDetailResponse.java @@ -0,0 +1,18 @@ +package com.example.letscareer.mid_review.dto.response; + +import jakarta.persistence.Lob; + +import java.time.LocalDate; + +public record MidReviewDetailResponse( + String company, + String department, + String type, + LocalDate deadline, + @Lob + String freeReview, + + @Lob + String goal +) { +} 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 26628e8..3795194 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 @@ -14,4 +14,6 @@ public interface MidReviewRepository extends JpaRepository { Boolean existsByStage(Stage stage); @Query("SELECT mr.midReviewId FROM MidReview mr WHERE mr.stage = :stage AND mr.user = :user") Optional findMidReviewIdByStageAndUser(Stage stage, User user); + + Optional findByMidReviewIdAndUser(Long midReviewId, User user); } 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 327b4dc..b9ca45e 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 @@ -4,6 +4,7 @@ import com.example.letscareer.int_review.repository.IntReviewRepository; import com.example.letscareer.mid_review.domain.MidReview; import com.example.letscareer.mid_review.dto.request.PostMidReviewRequest; +import com.example.letscareer.mid_review.dto.response.MidReviewDetailResponse; import com.example.letscareer.mid_review.repository.MidReviewRepository; import com.example.letscareer.schedule.domain.Schedule; import com.example.letscareer.schedule.repository.ScheduleRepository; @@ -28,6 +29,25 @@ public class MidReviewService { private final StageRepository stageRepository; private final UserRepository userRepository; + public MidReviewDetailResponse getMidReview(Long userId, Long scheduleId,Long stageId, Long midReviewId){ + User user = userRepository.findByUserId(userId) + .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); + MidReview midReview = midReviewRepository.findByMidReviewIdAndUser(midReviewId, user) + .orElseThrow(()-> new NotFoundException(MID_REVIEW_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)); + return new MidReviewDetailResponse( + schedule.getCompany(), + schedule.getDepartment(), + stage.getType().getValue(), + stage.getDate(), + midReview.getFreeReview(), + midReview.getGoal() + ); + } + @Transactional public void postMidReview(Long userId, Long scheduleId, Long stageId, PostMidReviewRequest request) { User user = userRepository.findById(userId) From 78cefeaa404d93b7e3657e8cabda3c99b3dc9de1 Mon Sep 17 00:00:00 2001 From: pkl0912 Date: Mon, 2 Sep 2024 20:16:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#43=20[feat]=20=EC=A4=91=EA=B0=84=ED=9A=8C?= =?UTF-8?q?=EA=B3=A0=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/enums/SuccessCode.java | 1 + .../controller/MidReviewController.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) 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 0d7ce31..0e3535e 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 @@ -19,6 +19,7 @@ public enum SuccessCode { TODO_TOGGLE_SUCCESS(HttpStatus.OK, "투두 토글 변경 성공입니다"), SAVE_CAREER_SUCCESS(HttpStatus.CREATED, "커리어 등록 성공"), GET_CAREER_DETAIL_SUCCESS(HttpStatus.OK, "커리어 상세 조회 성공"), + MID_REVIEW_GET_SUCCESS(HttpStatus.CREATED, "중간 전형 회고 가져오기 성공"), MID_REVIEW_SAVE_SUCCESS(HttpStatus.CREATED, "중간 전형 회고 추가 성공"), INT_REVIEW_SAVE_SUCCESS(HttpStatus.CREATED, "면접 회고 추가 성공"), SELF_INTRO_SAVE_SUCCESS(HttpStatus.CREATED, "자기소개 추가 성공"), diff --git a/src/main/java/com/example/letscareer/mid_review/controller/MidReviewController.java b/src/main/java/com/example/letscareer/mid_review/controller/MidReviewController.java index 4efef9a..8fbbaf3 100644 --- a/src/main/java/com/example/letscareer/mid_review/controller/MidReviewController.java +++ b/src/main/java/com/example/letscareer/mid_review/controller/MidReviewController.java @@ -3,10 +3,12 @@ import com.example.letscareer.common.dto.ApiResponse; import com.example.letscareer.common.dto.ErrorResponse; import com.example.letscareer.common.dto.SuccessNonDataResponse; +import com.example.letscareer.common.dto.SuccessResponse; import com.example.letscareer.common.exception.enums.SuccessCode; import com.example.letscareer.common.exception.model.BadRequestException; import com.example.letscareer.common.exception.model.NotFoundException; import com.example.letscareer.mid_review.dto.request.PostMidReviewRequest; +import com.example.letscareer.mid_review.dto.response.MidReviewDetailResponse; import com.example.letscareer.mid_review.service.MidReviewService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -16,6 +18,21 @@ public class MidReviewController { private final MidReviewService midReviewService; + @GetMapping("/review/mid") + public ApiResponse getMidReview( + @RequestHeader("userId") Long userId, + @RequestParam Long scheduleId, + @RequestParam Long stageId, + @RequestParam Long midReviewId + ){ + try { + MidReviewDetailResponse midReviewDetailResponse = midReviewService.getMidReview(userId, scheduleId, stageId, midReviewId); + return SuccessResponse.success(SuccessCode.MID_REVIEW_GET_SUCCESS, midReviewDetailResponse); + } catch (NotFoundException | BadRequestException e) { + return ErrorResponse.error(e.getErrorCode()); + } + } + @PostMapping("/schedules/{scheduleId}/stages/{stageId}/reviews/mid") public ApiResponse postMidReview(