Skip to content
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 @@ -61,6 +61,15 @@ public ResponseEntity<ApplicationsResponse> getApplicants(
.ok(result);
}

@GetMapping("/competitors")
public ResponseEntity<ApplicationsResponse> getApplicantsForUserCompetitors(
Principal principal) {
applicationQueryService.validateSiteUserCanViewApplicants(principal.getName());
ApplicationsResponse result = applicationQueryService.getApplicantsByUserApplications(principal.getName());
return ResponseEntity
.ok(result);
}

@GetMapping("/status")
public ResponseEntity<VerifyStatusResponse> getApplicationVerifyStatus(Principal principal) {
VerifyStatusResponse result = verifyStatusQueryService.getVerifyStatus(principal.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class ApplicationQueryService {
@Transactional(readOnly = true)
@ThunderingHerdCaching(key = "application:query:{1}:{2}", cacheManager = "customCacheManager", ttlSec = 86400)
public ApplicationsResponse getApplicants(String email, String regionCode, String keyword) {
// 유저가 다른 지원자들을 볼 수 있는지 검증
SiteUser siteUser = siteUserRepository.getByEmail(email);

// 국가와 키워드와 지역을 통해 대학을 필터링한다.
Expand All @@ -60,6 +59,24 @@ public ApplicationsResponse getApplicants(String email, String regionCode, Strin
return new ApplicationsResponse(firstChoiceApplicants, secondChoiceApplicants, thirdChoiceApplicants);
}

@Transactional(readOnly = true)
public ApplicationsResponse getApplicantsByUserApplications(String email) {
SiteUser siteUser = siteUserRepository.getByEmail(email);

Application userLatestApplication = applicationRepository.getApplicationBySiteUserAndTerm(siteUser, term);
List<University> userAppliedUniversities = List.of(
userLatestApplication.getFirstChoiceUniversity().getUniversity(),
userLatestApplication.getSecondChoiceUniversity().getUniversity(),
userLatestApplication.getThirdChoiceUniversity().getUniversity()
);


List<UniversityApplicantsResponse> firstChoiceApplicants = getFirstChoiceApplicants(userAppliedUniversities, siteUser, term);
List<UniversityApplicantsResponse> secondChoiceApplicants = getSecondChoiceApplicants(userAppliedUniversities, siteUser, term);
List<UniversityApplicantsResponse> thirdChoiceApplicants = getThirdChoiceApplicants(userAppliedUniversities, siteUser, term);
return new ApplicationsResponse(firstChoiceApplicants, secondChoiceApplicants, thirdChoiceApplicants);
}

// 학기별로 상태가 관리된다.
// 금학기에 지원이력이 있는 사용자만 지원정보를 확인할 수 있도록 한다.
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,44 @@ public void setUpUserAndToken() {
List.of(ApplicantResponse.of(사용자4_이전학기_지원정보, false)))
));
}

@Test
void 내가_지원한_대학의_지원자를_조회한다() {
ApplicationsResponse response = RestAssured.given().log().all()
.header("Authorization", "Bearer " + accessToken)
.when().log().all()
.get("/application/competitors")
.then().log().all()
.statusCode(200)
.extract().as(ApplicationsResponse.class);

List<UniversityApplicantsResponse> firstChoiceApplicants = response.firstChoice();
List<UniversityApplicantsResponse> secondChoiceApplicants = response.secondChoice();
List<UniversityApplicantsResponse> thirdChoiceApplicants = response.thirdChoice();

assertThat(firstChoiceApplicants).containsExactlyInAnyOrder(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of(ApplicantResponse.of(사용자1_지원정보, false))),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true))),
UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보, List.of()));
assertThat(secondChoiceApplicants).containsExactlyInAnyOrder(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true))),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of(ApplicantResponse.of(사용자1_지원정보, false))),
UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보,
List.of()));
assertThat(thirdChoiceApplicants).containsExactlyInAnyOrder(
UniversityApplicantsResponse.of(괌대학_A_지원_정보,
List.of()),
UniversityApplicantsResponse.of(괌대학_B_지원_정보,
List.of()),
UniversityApplicantsResponse.of(린츠_카톨릭대학_지원_정보,
List.of(ApplicantResponse.of(나의_지원정보, true))));

assertThat(firstChoiceApplicants.size()).isEqualTo(3);
assertThat(secondChoiceApplicants.size()).isEqualTo(3);
assertThat(thirdChoiceApplicants.size()).isEqualTo(3);
}
}