diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitCreateRequest.java b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitCreateRequest.java index f838f19..82d0962 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitCreateRequest.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitCreateRequest.java @@ -1,7 +1,6 @@ package com.server.bbo_gak.domain.recruit.dto.request; import com.server.bbo_gak.domain.recruit.entity.Recruit; -import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage; import com.server.bbo_gak.domain.recruit.entity.RecruitStatus; import com.server.bbo_gak.domain.recruit.entity.Season; import com.server.bbo_gak.domain.user.entity.User; @@ -10,7 +9,7 @@ public record RecruitCreateRequest( String season, String title, String siteUrl, - RecruitScheduleStage recruitScheduleStage, + String recruitScheduleStage, String deadline ) { diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitUpdateStatusRequest.java b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitUpdateStatusRequest.java index b442c38..8f97505 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitUpdateStatusRequest.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/dto/request/RecruitUpdateStatusRequest.java @@ -1,7 +1,5 @@ package com.server.bbo_gak.domain.recruit.dto.request; -import com.server.bbo_gak.domain.recruit.entity.RecruitStatus; - -public record RecruitUpdateStatusRequest(RecruitStatus recruitStatus) { +public record RecruitUpdateStatusRequest(String recruitStatus) { } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitScheduleStage.java b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitScheduleStage.java index f2603a7..f0945b7 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitScheduleStage.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitScheduleStage.java @@ -1,5 +1,8 @@ package com.server.bbo_gak.domain.recruit.entity; +import com.server.bbo_gak.global.error.exception.ErrorCode; +import com.server.bbo_gak.global.error.exception.NotFoundException; +import java.util.Arrays; import lombok.AllArgsConstructor; import lombok.Getter; @@ -14,4 +17,11 @@ public enum RecruitScheduleStage { FINAL_INTERVIEW("최종 면접"); private final String Value; + + public static RecruitScheduleStage findByValue(String value) { + return Arrays.stream(RecruitScheduleStage.values()) + .filter(scheduleStage -> scheduleStage.getValue().equals(value)) + .findFirst() + .orElseThrow((() -> new NotFoundException(ErrorCode.RECRUIT_SCHEDULE_STAGE_NOT_FOUND))); + } } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitStatus.java b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitStatus.java index cfdd79e..a4fa5e3 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitStatus.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/entity/RecruitStatus.java @@ -1,5 +1,8 @@ package com.server.bbo_gak.domain.recruit.entity; +import com.server.bbo_gak.global.error.exception.ErrorCode; +import com.server.bbo_gak.global.error.exception.NotFoundException; +import java.util.Arrays; import lombok.AllArgsConstructor; import lombok.Getter; @@ -16,6 +19,12 @@ public enum RecruitStatus { FINAL_ACCEPTANCE("최종 합격"), FINAL_REJECTED("최종 탈락"); - private final String value; + + public static RecruitStatus findByValue(String value) { + return Arrays.stream(RecruitStatus.values()) + .filter(recruitStatus -> recruitStatus.getValue().equals(value)) + .findFirst() + .orElseThrow((() -> new NotFoundException(ErrorCode.RECRUIT_STATUS_NOT_FOUND))); + } } diff --git a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java index 2a7985f..dbfdb6e 100644 --- a/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java +++ b/src/main/java/com/server/bbo_gak/domain/recruit/service/RecruitService.java @@ -5,6 +5,7 @@ import com.server.bbo_gak.domain.recruit.dto.response.RecruitGetResponse; import com.server.bbo_gak.domain.recruit.entity.Recruit; import com.server.bbo_gak.domain.recruit.entity.RecruitSchedule; +import com.server.bbo_gak.domain.recruit.entity.RecruitScheduleStage; import com.server.bbo_gak.domain.recruit.entity.RecruitStatus; import com.server.bbo_gak.domain.recruit.entity.RecruitStatusCategory; import com.server.bbo_gak.domain.recruit.entity.Season; @@ -98,7 +99,8 @@ public RecruitGetResponse createRecruit(User user, RecruitCreateRequest request) // 공고 일정 생성 RecruitSchedule recruitSchedule = recruitScheduleService.createRecruitSchedule( - RecruitSchedule.of(recruit, request.recruitScheduleStage(), request.deadline()) + RecruitSchedule.of(recruit, RecruitScheduleStage.findByValue(request.recruitScheduleStage()), + request.deadline()) ); // 공고에 공고 일정을 설정 @@ -134,10 +136,10 @@ public RecruitGetResponse updateRecruitSeason(User user, Long recruitId, String } @Transactional - public RecruitGetResponse updateRecruitStatus(User user, Long recruitId, RecruitStatus recruitStatus) { + public RecruitGetResponse updateRecruitStatus(User user, Long recruitId, String recruitStatus) { Recruit recruit = findRecruitByUserAndId(user, recruitId); - recruit.updateRecruitStatus(recruitStatus); + recruit.updateRecruitStatus(RecruitStatus.findByValue(recruitStatus)); return RecruitGetResponse.from(recruitRepository.save(recruit)); } diff --git a/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java b/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java index 11107a7..6285e9d 100644 --- a/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java +++ b/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java @@ -47,6 +47,9 @@ public enum ErrorCode { //Recruit RECRUIT_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 공고를 찾을 수 없습니다"), + RECRUIT_STATUS_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 공고 지원 상태를 찾을 수 없습니다"), + RECRUIT_SCHEDULE_STAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 공고 일정 단계를 찾을 수 없습니다"), + CARD_TAG_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 카드와 태그 매핑을 찾을 수 없습니다"), diff --git a/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitControllerTest.java b/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitControllerTest.java index 3392423..a34a149 100644 --- a/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitControllerTest.java +++ b/src/test/java/com/server/bbo_gak/domain/recruit/controller/RecruitControllerTest.java @@ -130,7 +130,8 @@ class 공고상태_업데이트 { @Test public void 성공() throws Exception { - RecruitUpdateStatusRequest request = new RecruitUpdateStatusRequest(RecruitStatus.APPLICATION_COMPLETED); + RecruitUpdateStatusRequest request = + new RecruitUpdateStatusRequest(RecruitStatus.APPLICATION_COMPLETED.getValue()); mockMvc.perform( restDocsFactory.createRequest(DEFAULT_URL + "/{id}/status", request, HttpMethod.PATCH, objectMapper, @@ -142,7 +143,20 @@ class 공고상태_업데이트 { @Test public void 찾을수_없음_실패() throws Exception { - RecruitUpdateStatusRequest request = new RecruitUpdateStatusRequest(RecruitStatus.APPLICATION_COMPLETED); + RecruitUpdateStatusRequest request = + new RecruitUpdateStatusRequest(RecruitStatus.APPLICATION_COMPLETED.getValue()); + + mockMvc.perform( + restDocsFactory.createRequest(DEFAULT_URL + "/{id}/status", request, HttpMethod.PATCH, objectMapper, + 100L)) + .andExpect(status().isNotFound()) + .andDo(restDocsFactory.getFailureResource("[PATCH] 상태 수정 실패", "Recruit", request)); + } + + @Test + public void 존재하지않는_상태_실패() throws Exception { + RecruitUpdateStatusRequest request = + new RecruitUpdateStatusRequest("지원 준비 중"); mockMvc.perform( restDocsFactory.createRequest(DEFAULT_URL + "/{id}/status", request, HttpMethod.PATCH, objectMapper, @@ -189,7 +203,7 @@ class 공고_생성 { "2024 상반기", "New Recruit Title", "https://example.com", - RecruitScheduleStage.CLOSING_DOCUMENT, + RecruitScheduleStage.CLOSING_DOCUMENT.getValue(), "2024-12-31" ); @@ -198,6 +212,21 @@ class 공고_생성 { .andDo(restDocsFactory.getSuccessResource("[POST] 공고 생성 성공", "공고 생성", "Recruit", request, response)); } + + @Test + public void 실패() throws Exception { + RecruitCreateRequest request = new RecruitCreateRequest( + "2024 상반기", + "New Recruit Title", + "https://example.com", + "서류통과", + "2024-12-31" + ); + + mockMvc.perform(restDocsFactory.createRequest(DEFAULT_URL, request, HttpMethod.POST, objectMapper)) + .andExpect(status().isNotFound()) + .andDo(restDocsFactory.getFailureResource("[POST] 공고 생성 실패", "Recruit", request)); + } } @Nested