Skip to content

Commit

Permalink
feat-be: 다중 불합격자 해제 기능 구현 (#759)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kwoun Ki Ho <[email protected]>
  • Loading branch information
github-actions[bot] and Chocochip101 committed Oct 5, 2024
1 parent 4c60d92 commit 2e05f2b
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 4 deletions.
14 changes: 14 additions & 0 deletions backend/src/docs/asciidoc/applicant.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,17 @@ operation::applicant/reject-all-fail/applicant-not-found[snippets="http-request,
==== 실패: 이미 불합격한 지원자

operation::applicant/reject-all-fail/already-rejected[snippets="http-request,request-cookies,request-fields,http-response"]

=== 지원자 일괄 불합격 해제

==== 성공

operation::applicant/unreject-all/[snippets="http-request,request-cookies,request-fields,http-response"]

==== 실패: 존재하지 않는 지원자

operation::applicant/unreject-all-fail/applicant-not-found[snippets="http-request,request-cookies,request-fields,http-response"]

==== 실패: 불합격 하지 않은 지원자

operation::applicant/unreject-all-fail/already-unrejected[snippets="http-request,request-cookies,request-fields,http-response"]
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,12 @@ public ResponseEntity<Void> reject(@RequestBody @Valid ApplicantsRejectRequest r
applicantFacade.reject(request);
return ResponseEntity.ok().build();
}

@PatchMapping("/unreject")
public ResponseEntity<Void> unreject(
@RequestBody @Valid ApplicantsRejectRequest request, LoginProfile loginProfile
) {
applicantFacade.unreject(request);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface ApplicantRepository extends JpaRepository<Applicant, Long> {

Expand Down Expand Up @@ -47,5 +48,6 @@ a.id, a.name, a.createdDate, a.isRejected, COUNT(e), COALESCE(AVG(e.score), 0.00
SET a.isRejected = :isRejected
WHERE a.id in :applicantIds
""")
@Transactional
void updateRejectedStatusForApplicants(List<Long> applicantIds, boolean isRejected);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public void unreject(long applicantId) {
public void reject(ApplicantsRejectRequest request) {
applicantService.reject(request.applicantIds());
}

@Transactional
public void unreject(ApplicantsRejectRequest request) {
applicantService.unreject(request.applicantIds());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ private void validateUnrejectable(Applicant applicant) {
}
}

@Transactional
public void unreject(List<Long> applicantIds) {
applicantIds.stream()
.map(this::findById)
.forEach(this::validateUnrejectable);

applicantRepository.updateRejectedStatusForApplicants(applicantIds, false);
}

public ApplicantResponse toApplicantResponse(Applicant applicant) {
return new ApplicantResponse(
applicant.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,8 @@ void rejectAll_applicantNotFound() {
@Test
void rejectAll_alreadyReject() {
// given
Applicant applicant = ApplicantFixture.pendingDobby();
applicant.reject();
Applicant savedApplicant = applicantRepository.save(applicant);
ApplicantsRejectRequest request = new ApplicantsRejectRequest(List.of(savedApplicant.getId()));
Applicant applicant = applicantRepository.save(ApplicantFixture.rejectedRush());
ApplicantsRejectRequest request = new ApplicantsRejectRequest(List.of(applicant.getId()));

// when&then
RestAssured.given(spec).log().all()
Expand All @@ -432,4 +430,67 @@ void rejectAll_alreadyReject() {
.when().patch("/v1/applicants/reject")
.then().log().all().statusCode(400);
}

@DisplayName("모든 지원자를 불합격 해제시키는데 성공하면 200을 응답한다.")
@Test
void unrejectAll() {
// given
Applicant applicant1 = applicantRepository.save(ApplicantFixture.rejectedRush());
Applicant applicant2 = applicantRepository.save(ApplicantFixture.rejectedRush());
ApplicantsRejectRequest request = new ApplicantsRejectRequest(List.of(applicant1.getId(), applicant2.getId()));

// when&then
RestAssured.given(spec).log().all()
.cookie("token", token)
.contentType(ContentType.JSON)
.body(request)
.filter(document(
"applicant/unreject-all/",
requestCookies(cookieWithName("token").description("사용자 토큰")),
requestFields(fieldWithPath("applicantIds").description("불합격 해제시킬 지원자들의 id"))
))
.when().patch("/v1/applicants/unreject")
.then().log().all().statusCode(200);
}

@DisplayName("존재하지 않는 지원자 불합격 해제 시, 404를 응답한다.")
@Test
void unrejectAll_applicantNotFound() {
// given
ApplicantsRejectRequest request = new ApplicantsRejectRequest(List.of(-1L));

// when&then
RestAssured.given(spec).log().all()
.cookie("token", token)
.contentType(ContentType.JSON)
.body(request)
.filter(document(
"applicant/unreject-all-fail/applicant-not-found/",
requestCookies(cookieWithName("token").description("사용자 토큰")),
requestFields(fieldWithPath("applicantIds").description("존재하지 않는 지원자의 id"))
))
.when().patch("/v1/applicants/unreject")
.then().log().all().statusCode(404);
}

@DisplayName("불합격 한 지원자 불합격 해제 시, 400를 응답한다.")
@Test
void unrejectAll_alreadyUnreject() {
// given
Applicant applicant = applicantRepository.save(ApplicantFixture.pendingDobby());
ApplicantsRejectRequest request = new ApplicantsRejectRequest(List.of(applicant.getId()));

// when&then
RestAssured.given(spec).log().all()
.cookie("token", token)
.contentType(ContentType.JSON)
.body(request)
.filter(document(
"applicant/unreject-all-fail/already-unrejected/",
requestCookies(cookieWithName("token").description("사용자 토큰")),
requestFields(fieldWithPath("applicantIds").description("불합격하지 않은 지원자의 id"))
))
.when().patch("/v1/applicants/unreject")
.then().log().all().statusCode(400);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,27 @@ void rejectAll() {
() -> assertThat(foundApplicant2.isRejected()).isTrue()
);
}

@DisplayName("모든 지원자 불합격 해제시킨다.")
@Test
void unrejectAll() {
// given
Applicant applicant1 = applicantRepository.save(ApplicantFixture.rejectedRush());
Applicant applicant2 = applicantRepository.save(ApplicantFixture.rejectedRush());

ApplicantsRejectRequest request = new ApplicantsRejectRequest(List.of(applicant1.getId(), applicant2.getId()));

// when
applicantFacade.unreject(request);

// then
Applicant foundApplicant1 = applicantRepository.findById(applicant1.getId())
.orElseThrow();
Applicant foundApplicant2 = applicantRepository.findById(applicant2.getId())
.orElseThrow();
assertAll(
() -> assertThat(foundApplicant1.isRejected()).isFalse(),
() -> assertThat(foundApplicant2.isRejected()).isFalse()
);
}
}

0 comments on commit 2e05f2b

Please sign in to comment.