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

#57 [feat] 4.2 서류전형 상세 조회 기능 구현 #58

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<AppealCareer, Long> {
List<AppealCareer> findByStage(Stage stage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, "지원하지 않는 메소드 입니다."),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SelfIntro, Long> {
void deleteByStage(Stage stage);

List<SelfIntro> findByStage(Stage stage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.letscareer.stage.dto;

public record AppealCareerDTO(
Long careerId,
String category,
String title
) {
}
Original file line number Diff line number Diff line change
@@ -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<SelfIntroDTO> selfIntroductions,
List<AppealCareerDTO> appealCareers
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,4 +30,6 @@ public interface StageRepository extends JpaRepository<Stage, Long> {
List<Stage> findAllBySchedule(Schedule schedule);

List<Stage> findBySchedule(Schedule schedule);

Optional<Stage> findByScheduleAndStageIdAndType(Schedule schedule, Long stageId, Type type);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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<SelfIntro> selfIntros = selfIntroRepository.findByStage(stage);
List<SelfIntroDTO> selfIntroDTOs = new ArrayList<>();
for(SelfIntro selfIntro : selfIntros) {
selfIntroDTOs.add(
new SelfIntroDTO(
selfIntro.getTitle(),
selfIntro.getSequence(),
selfIntro.getContent()
)
);
}

List<AppealCareer> appealCareers = appealCareerRepository.findByStage(stage);
List<AppealCareerDTO> 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
);
}
}
Loading