Skip to content

Commit

Permalink
feat: 지원자가 본인의 지원서를 조회하는 api
Browse files Browse the repository at this point in the history
  • Loading branch information
jongmee committed Aug 26, 2024
1 parent 4a87dc9 commit 8446c90
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ public ApplicationDetailsResponse findApplicationDetails(Long applicationId, Lon
return ApplicationDetailsResponse.of(application, narrativeAnswers, selectiveAnswers);
}

public ApplicationDetailsResponse findMyApplicationDetails(Long applicantId, String code) {
Application application = applicationRepository.findByApplicantIdAndRecruitmentCode(applicantId, code)
.orElseThrow(() -> new CrewsException(ErrorCode.APPLICATION_NOT_FOUND));
List<NarrativeAnswer> narrativeAnswers = narrativeAnswerRepository.findAllByApplication(application);
Map<Long, List<SelectiveAnswer>> selectiveAnswers = collectSelectiveAnswersByQuestion(
selectiveAnswerRepository.findAllByApplication(application));
return ApplicationDetailsResponse.of(application, narrativeAnswers, selectiveAnswers);
}

private void checkPermission(Application application, Long publisherId) {
if (!application.canBeAccessedBy(publisherId)) {
throw new CrewsException(ErrorCode.UNAUTHORIZED_USER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -46,6 +47,15 @@ public ResponseEntity<ApplicationDetailsResponse> getApplicationDetails(
return ResponseEntity.ok(applicationService.findApplicationDetails(applicationId, loginUser.userId()));
}

/**
* 지원자가 본인의 지원서를 조회한다.
*/
@GetMapping("/mine")
public ResponseEntity<ApplicationDetailsResponse> getMyApplicationDetails(
@ApplicantAuthentication LoginUser loginUser, @RequestParam("code") String code) {
return ResponseEntity.ok(applicationService.findMyApplicationDetails(loginUser.userId(), code));
}

/**
* 한 공고의 모든 지원서 목록을 조회한다.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ select count(application) from Application application
where a.id = :id
""")
Optional<Application> findByIdWithRecruitmentAndPublisher(@Param("id") Long id);

@Query("""
select a from Application a
join fetch a.recruitment r
where a.applicant.id = :applicantId and r.code = :recruitmentCode
""")
Optional<Application> findByApplicantIdAndRecruitmentCode(@Param("applicantId") Long applicantId,
@Param("recruitmentCode") String recruitmentCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public static RestDocumentationFilter GET_APPLICATION_200_DOCUMENT() {
.pathParameters(parameterWithName("application-id").description("지원서 id")));
}

public static RestDocumentationFilter GET_MY_APPLICATION_200_DOCUMENT() {
return document(APPLICATION_API + "지원자 지원서 상세 조회",
new ResourceSnippetParametersBuilder().description("지원자가 본인의 지원서 상세 정보를 조회한다.")
.queryParameters(parameterWithName("code").description("모집공고 code")));
}

public static RestDocumentationFilter GET_APPLICATIONS_200_DOCUMENT() {
return document(APPLICATION_API + "지원서 목록 조회",
new ResourceSnippetParametersBuilder().description("지원서 목록을 조회한다."));
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/com/server/crews/api/ApplicationApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,39 @@ void getApplicationDetails() {
});
}

@Test
@DisplayName("지원자가 본인의 지원서 상세 정보를 조회한다.")
void getMyApplicationDetails() {
// given
AdminLoginResponse adminTokenResponse = signUpAdmin(TEST_CLUB_NAME, TEST_PASSWORD);
RecruitmentDetailsResponse recruitmentDetailsResponse = createRecruitment(adminTokenResponse.accessToken());
ApplicantLoginResponse applicantLoginResponse = signUpApplicant(TEST_EMAIL, TEST_PASSWORD);

ApplicationSaveRequest applicationSaveRequest = applicationSaveRequest(recruitmentDetailsResponse.code());
createTestApplication(applicantLoginResponse.accessToken(), applicationSaveRequest);

// when
ExtractableResponse<Response> response = RestAssured.given(spec).log().all()
.filter(ApplicationApiDocuments.GET_MY_APPLICATION_200_DOCUMENT())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.AUTHORIZATION,
AuthorizationExtractor.BEARER_TYPE + applicantLoginResponse.accessToken())
.queryParam("code", recruitmentDetailsResponse.code())
.when().get("/applications/mine")
.then().log().all()
.extract();

// then
ApplicationDetailsResponse applicationDetailsResponse = response.as(ApplicationDetailsResponse.class);
assertSoftly(softAssertions -> {
checkStatusCode200(response, softAssertions);
softAssertions.assertThat(applicationDetailsResponse.id()).isNotNull();
softAssertions.assertThat(applicationDetailsResponse.narrativeAnswers()).isNotEmpty();
softAssertions.assertThat(applicationDetailsResponse.selectiveAnswers())
.flatExtracting(SelectiveAnswerResponse::choices).isNotEmpty();
});
}

@Test
@DisplayName("지원서들을 평가한다.")
void evaluate() {
Expand Down

0 comments on commit 8446c90

Please sign in to comment.