From 8f9ebb7ced273c06410f9ead47d95fb1807d4fc6 Mon Sep 17 00:00:00 2001 From: devMuromi Date: Sat, 7 Sep 2024 18:53:56 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EB=82=B4=EA=B0=80=20=EC=A7=80?= =?UTF-8?q?=EC=9B=90=ED=95=9C=20=EB=8C=80=ED=95=99=EC=9D=98=20=EC=A7=80?= =?UTF-8?q?=EC=9B=90=EC=84=9C=EB=A7=8C=20=EB=B3=BC=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20api=20endpoint=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApplicationController.java | 9 +++++++++ .../service/ApplicationQueryService.java | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) 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) From 7f3041290abaf6d122d1d4d36979d91538f4d69e Mon Sep 17 00:00:00 2001 From: devMuromi Date: Sat, 7 Sep 2024 18:55:51 +0900 Subject: [PATCH 2/2] =?UTF-8?q?test:=20/application/competitors=20e2e=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../e2e/ApplicantsQueryTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) 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); + } }