diff --git a/src/main/java/com/example/letscareer/appealCareer/repository/AppealCareerRepository.java b/src/main/java/com/example/letscareer/appealCareer/repository/AppealCareerRepository.java index e98a7d0..9bc0ada 100644 --- a/src/main/java/com/example/letscareer/appealCareer/repository/AppealCareerRepository.java +++ b/src/main/java/com/example/letscareer/appealCareer/repository/AppealCareerRepository.java @@ -1,9 +1,13 @@ package com.example.letscareer.appealCareer.repository; import com.example.letscareer.appealCareer.domain.AppealCareer; +import com.example.letscareer.stage.domain.Stage; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface AppealCareerRepository extends JpaRepository { + List findByStage(Stage stage); } 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 d8c5c2f..be30233 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 @@ -24,6 +24,7 @@ public enum ErrorCode { TODO_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 투두는 존재하지 않습니다"), 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의 서류전형 단계를 찾을 수 없습니다."), // 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 3a193a5..a6de88e 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 @@ -28,7 +28,8 @@ public enum SuccessCode { STAGE_ADD_SUCCESS(HttpStatus.CREATED, "전형 단계 추가 성공"), STAGE_UPDATE_SUCCESS(HttpStatus.OK, "전형 단계 상태 변경 성공"), UPDATE_SCHEDULE_PROGRESS_SUCCESS(HttpStatus.OK, "일정 진행 상태 변경 성공"), - STAGES_GET_SUCCESS(HttpStatus.OK, "지원 일정 및 단계 조회 성공"),; + STAGES_GET_SUCCESS(HttpStatus.OK, "지원 일정 및 단계 조회 성공"), + DOC_STAGES_GET_SUCCESS(HttpStatus.OK, "서류전형 단계 조회 성공"),; private final HttpStatus httpStatus; private final String message; diff --git a/src/main/java/com/example/letscareer/self_intro/repository/SelfIntroRepository.java b/src/main/java/com/example/letscareer/self_intro/repository/SelfIntroRepository.java index dbd33af..da4a200 100644 --- a/src/main/java/com/example/letscareer/self_intro/repository/SelfIntroRepository.java +++ b/src/main/java/com/example/letscareer/self_intro/repository/SelfIntroRepository.java @@ -2,10 +2,15 @@ import com.example.letscareer.self_intro.domain.SelfIntro; import com.example.letscareer.stage.domain.Stage; +import com.example.letscareer.user.domain.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface SelfIntroRepository extends JpaRepository { void deleteByStage(Stage stage); + + List 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 a307fb9..ecd29e8 100644 --- a/src/main/java/com/example/letscareer/stage/controller/StageController.java +++ b/src/main/java/com/example/letscareer/stage/controller/StageController.java @@ -62,4 +62,17 @@ public ApiResponse getStages( return ErrorResponse.error(e.getErrorCode()); } } + + @GetMapping("/schedules/{scheduleId}/stages/{stageId}/document") + public ApiResponse getDocumentStage( + @RequestHeader("userId") Long userId, + @PathVariable Long scheduleId, + @PathVariable Long stageId + ) { + try { + return SuccessResponse.success(SuccessCode.DOC_STAGES_GET_SUCCESS , stageService.getDocumentStage(userId, scheduleId, stageId)); + } catch (NotFoundException | BadRequestException e) { + return ErrorResponse.error(e.getErrorCode()); + } + } } diff --git a/src/main/java/com/example/letscareer/stage/dto/AppealCareerDTO.java b/src/main/java/com/example/letscareer/stage/dto/AppealCareerDTO.java new file mode 100644 index 0000000..4bbbf0d --- /dev/null +++ b/src/main/java/com/example/letscareer/stage/dto/AppealCareerDTO.java @@ -0,0 +1,8 @@ +package com.example.letscareer.stage.dto; + +public record AppealCareerDTO( + Long careerId, + String category, + String title +) { +} diff --git a/src/main/java/com/example/letscareer/stage/dto/response/GetDocumentStageResponse.java b/src/main/java/com/example/letscareer/stage/dto/response/GetDocumentStageResponse.java new file mode 100644 index 0000000..95d25d8 --- /dev/null +++ b/src/main/java/com/example/letscareer/stage/dto/response/GetDocumentStageResponse.java @@ -0,0 +1,14 @@ +package com.example.letscareer.stage.dto.response; + +import com.example.letscareer.self_intro.dto.SelfIntroDTO; +import com.example.letscareer.stage.dto.AppealCareerDTO; + +import java.util.List; + +public record GetDocumentStageResponse( + Long stageId, + String type, + List selfIntroductions, + List appealCareers +) { +} diff --git a/src/main/java/com/example/letscareer/stage/repository/StageRepository.java b/src/main/java/com/example/letscareer/stage/repository/StageRepository.java index 0f4decd..eeb87f5 100644 --- a/src/main/java/com/example/letscareer/stage/repository/StageRepository.java +++ b/src/main/java/com/example/letscareer/stage/repository/StageRepository.java @@ -2,6 +2,8 @@ import com.example.letscareer.schedule.domain.Schedule; import com.example.letscareer.stage.domain.Stage; +import com.example.letscareer.stage.domain.Type; +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; @@ -28,4 +30,6 @@ public interface StageRepository extends JpaRepository { List findAllBySchedule(Schedule schedule); List findBySchedule(Schedule schedule); + + Optional findByScheduleAndStageIdAndType(Schedule schedule, Long stageId, Type type); } 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 d781ead..19176e9 100644 --- a/src/main/java/com/example/letscareer/stage/service/StageService.java +++ b/src/main/java/com/example/letscareer/stage/service/StageService.java @@ -1,15 +1,22 @@ package com.example.letscareer.stage.service; +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.schedule.domain.Schedule; import com.example.letscareer.schedule.repository.ScheduleRepository; +import com.example.letscareer.self_intro.domain.SelfIntro; +import com.example.letscareer.self_intro.dto.SelfIntroDTO; +import com.example.letscareer.self_intro.repository.SelfIntroRepository; import com.example.letscareer.stage.domain.Stage; 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.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.GetStagesResponse; import com.example.letscareer.stage.repository.StageRepository; import com.example.letscareer.user.domain.User; @@ -34,6 +41,8 @@ public class StageService { private final StageRepository stageRepository; private final ScheduleRepository scheduleRepository; private final UserRepository userRepository; + private final SelfIntroRepository selfIntroRepository; + private final AppealCareerRepository appealCareerRepository; @Transactional public AddStageResponse addStage(Long userId, Long scheduleId, AddStageRequest request) { @@ -118,4 +127,44 @@ public GetStagesResponse getStages(Long userId, Long scheduleId) { schedule.isAlways(), stageDTOs); } + + public GetDocumentStageResponse getDocumentStage(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.DOC) + .orElseThrow(() -> new NotFoundException(DOC_STAGE_NOT_FOUND_EXCEPTION)); + + List selfIntros = selfIntroRepository.findByStage(stage); + List selfIntroDTOs = new ArrayList<>(); + for(SelfIntro selfIntro : selfIntros) { + selfIntroDTOs.add( + new SelfIntroDTO( + selfIntro.getTitle(), + selfIntro.getSequence(), + selfIntro.getContent() + ) + ); + } + + List appealCareers = appealCareerRepository.findByStage(stage); + List appealCareerDTOs = new ArrayList<>(); + for(AppealCareer appealCareer : appealCareers) { + appealCareerDTOs.add( + new AppealCareerDTO( + appealCareer.getCareer().getCareerId(), + appealCareer.getCareer().getCategory().getValue(), + appealCareer.getCareer().getTitle() + ) + ); + } + + return new GetDocumentStageResponse( + stage.getStageId(), + stage.getType().getValue(), + selfIntroDTOs, + appealCareerDTOs + ); + } }