Skip to content

Commit

Permalink
[fix][#61]공고 일정, 공고 상태 알맞은 value값 아닐시 404 에러
Browse files Browse the repository at this point in the history
  • Loading branch information
sejoon00 committed Aug 20, 2024
1 parent 3a423f9 commit d2d2d22
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,7 +9,7 @@ public record RecruitCreateRequest(
String season,
String title,
String siteUrl,
RecruitScheduleStage recruitScheduleStage,
String recruitScheduleStage,
String deadline
) {

Expand Down
Original file line number Diff line number Diff line change
@@ -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) {

}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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)));
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
);

// 공고에 공고 일정을 설정
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "해당 카드와 태그 매핑을 찾을 수 없습니다"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -189,7 +203,7 @@ class 공고_생성 {
"2024 상반기",
"New Recruit Title",
"https://example.com",
RecruitScheduleStage.CLOSING_DOCUMENT,
RecruitScheduleStage.CLOSING_DOCUMENT.getValue(),
"2024-12-31"
);

Expand All @@ -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
Expand Down

0 comments on commit d2d2d22

Please sign in to comment.