diff --git a/src/main/java/com/example/solidconnection/application/controller/ApplicationController.java b/src/main/java/com/example/solidconnection/application/controller/ApplicationController.java index baf5159a1..d6695df28 100644 --- a/src/main/java/com/example/solidconnection/application/controller/ApplicationController.java +++ b/src/main/java/com/example/solidconnection/application/controller/ApplicationController.java @@ -61,6 +61,15 @@ public ResponseEntity getApplicants( .ok(result); } + @GetMapping("/competitors") + public ResponseEntity getApplicantsForUserCompetitors( + Principal principal) { + applicationQueryService.validateSiteUserCanViewApplicants(principal.getName()); + ApplicationsResponse result = applicationQueryService.getApplicantsByUserApplications(principal.getName()); + return ResponseEntity + .ok(result); + } + @GetMapping("/status") public ResponseEntity getApplicationVerifyStatus(Principal principal) { VerifyStatusResponse result = verifyStatusQueryService.getVerifyStatus(principal.getName()); diff --git a/src/main/java/com/example/solidconnection/application/service/ApplicationQueryService.java b/src/main/java/com/example/solidconnection/application/service/ApplicationQueryService.java index aee3ad25e..fff928f05 100644 --- a/src/main/java/com/example/solidconnection/application/service/ApplicationQueryService.java +++ b/src/main/java/com/example/solidconnection/application/service/ApplicationQueryService.java @@ -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); // 국가와 키워드와 지역을 통해 대학을 필터링한다. @@ -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 userAppliedUniversities = List.of( + userLatestApplication.getFirstChoiceUniversity().getUniversity(), + userLatestApplication.getSecondChoiceUniversity().getUniversity(), + userLatestApplication.getThirdChoiceUniversity().getUniversity() + ); + + + List firstChoiceApplicants = getFirstChoiceApplicants(userAppliedUniversities, siteUser, term); + List secondChoiceApplicants = getSecondChoiceApplicants(userAppliedUniversities, siteUser, term); + List thirdChoiceApplicants = getThirdChoiceApplicants(userAppliedUniversities, siteUser, term); + return new ApplicationsResponse(firstChoiceApplicants, secondChoiceApplicants, thirdChoiceApplicants); + } + // 학기별로 상태가 관리된다. // 금학기에 지원이력이 있는 사용자만 지원정보를 확인할 수 있도록 한다. @Transactional(readOnly = true) diff --git a/src/test/java/com/example/solidconnection/e2e/ApplicantsQueryTest.java b/src/test/java/com/example/solidconnection/e2e/ApplicantsQueryTest.java index cb5fbfe52..7dd8b63f9 100644 --- a/src/test/java/com/example/solidconnection/e2e/ApplicantsQueryTest.java +++ b/src/test/java/com/example/solidconnection/e2e/ApplicantsQueryTest.java @@ -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 firstChoiceApplicants = response.firstChoice(); + List secondChoiceApplicants = response.secondChoice(); + List 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); + } }