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

#59 [feat] 4.3 중간전형 상세 조회 기능 구현 #60

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
Expand Up @@ -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, "지원하지 않는 메소드 입니다."),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface MidReviewRepository extends JpaRepository<MidReview, Long> {
Optional<Long> findMidReviewIdByStageAndUser(Stage stage, User user);

Optional<MidReview> findByMidReviewIdAndUser(Long midReviewId, User user);

Optional<MidReview> findByStage(Stage stage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/example/letscareer/stage/dto/ReviewDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.letscareer.stage.dto;

import java.time.LocalDate;

public record ReviewDTO(
Long reviewId,
String free_review,
String goal
) {
}
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.*;

Expand All @@ -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) {
Expand Down Expand Up @@ -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> 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
);
}
}
}
Loading