diff --git a/src/main/java/com/example/solidconnection/admin/controller/AdminMentorApplicationController.java b/src/main/java/com/example/solidconnection/admin/controller/AdminMentorApplicationController.java index 1c64df14..b8fe6974 100644 --- a/src/main/java/com/example/solidconnection/admin/controller/AdminMentorApplicationController.java +++ b/src/main/java/com/example/solidconnection/admin/controller/AdminMentorApplicationController.java @@ -1,5 +1,6 @@ package com.example.solidconnection.admin.controller; +import com.example.solidconnection.admin.dto.MentorApplicationAssignUniversityRequest; import com.example.solidconnection.admin.dto.MentorApplicationCountResponse; import com.example.solidconnection.admin.dto.MentorApplicationRejectRequest; import com.example.solidconnection.admin.dto.MentorApplicationSearchCondition; @@ -40,17 +41,17 @@ public ResponseEntity> searchMento return ResponseEntity.ok(PageResponse.of(page)); } - @PostMapping("/{mentorApplicationId}/approve") + @PostMapping("/{mentor-application-id}/approve") public ResponseEntity approveMentorApplication( - @PathVariable("mentorApplicationId") Long mentorApplicationId + @PathVariable("mentor-application-id") Long mentorApplicationId ) { adminMentorApplicationService.approveMentorApplication(mentorApplicationId); return ResponseEntity.ok().build(); } - @PostMapping("/{mentorApplicationId}/reject") + @PostMapping("/{mentor-application-id}/reject") public ResponseEntity rejectMentorApplication( - @PathVariable("mentorApplicationId") Long mentorApplicationId, + @PathVariable("mentor-application-id") Long mentorApplicationId, @Valid @RequestBody MentorApplicationRejectRequest request ) { adminMentorApplicationService.rejectMentorApplication(mentorApplicationId, request); @@ -62,4 +63,14 @@ public ResponseEntity getMentorApplicationCount( MentorApplicationCountResponse response = adminMentorApplicationService.getMentorApplicationCount(); return ResponseEntity.ok(response); } + + @PostMapping("/{mentor-application-id}/assign-university") + public ResponseEntity assignUniversity( + @PathVariable("mentor-application-id") Long mentorApplicationId, + @Valid @RequestBody MentorApplicationAssignUniversityRequest request + ) { + Long universityId = request.universityId(); + adminMentorApplicationService.assignUniversity(mentorApplicationId, universityId); + return ResponseEntity.ok().build(); + } } diff --git a/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationAssignUniversityRequest.java b/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationAssignUniversityRequest.java new file mode 100644 index 00000000..6fdd8c6e --- /dev/null +++ b/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationAssignUniversityRequest.java @@ -0,0 +1,10 @@ +package com.example.solidconnection.admin.dto; + +import jakarta.validation.constraints.NotNull; + +public record MentorApplicationAssignUniversityRequest( + @NotNull(message = "대학 ID 는 필수입니다.") + Long universityId +) { + +} diff --git a/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationResponse.java b/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationResponse.java index 1fafc2df..5b6d6cc1 100644 --- a/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationResponse.java +++ b/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationResponse.java @@ -1,6 +1,7 @@ package com.example.solidconnection.admin.dto; import com.example.solidconnection.mentor.domain.MentorApplicationStatus; +import com.example.solidconnection.mentor.domain.UniversitySelectType; import java.time.ZonedDateTime; public record MentorApplicationResponse( @@ -8,6 +9,7 @@ public record MentorApplicationResponse( String region, String country, String university, + UniversitySelectType universitySelectType, String mentorProofUrl, MentorApplicationStatus mentorApplicationStatus, String rejectedReason, diff --git a/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationSearchCondition.java b/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationSearchCondition.java index 9871ba6d..940d2369 100644 --- a/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationSearchCondition.java +++ b/src/main/java/com/example/solidconnection/admin/dto/MentorApplicationSearchCondition.java @@ -1,12 +1,14 @@ package com.example.solidconnection.admin.dto; import com.example.solidconnection.mentor.domain.MentorApplicationStatus; +import com.example.solidconnection.mentor.domain.UniversitySelectType; import java.time.LocalDate; public record MentorApplicationSearchCondition( MentorApplicationStatus mentorApplicationStatus, String keyword, - LocalDate createdAt + LocalDate createdAt, + UniversitySelectType universitySelectType ) { -} \ No newline at end of file +} diff --git a/src/main/java/com/example/solidconnection/admin/service/AdminMentorApplicationService.java b/src/main/java/com/example/solidconnection/admin/service/AdminMentorApplicationService.java index 2c8ab494..d22d9af7 100644 --- a/src/main/java/com/example/solidconnection/admin/service/AdminMentorApplicationService.java +++ b/src/main/java/com/example/solidconnection/admin/service/AdminMentorApplicationService.java @@ -1,7 +1,6 @@ package com.example.solidconnection.admin.service; import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_NOT_FOUND; -import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED; import com.example.solidconnection.admin.dto.MentorApplicationCountResponse; import com.example.solidconnection.admin.dto.MentorApplicationRejectRequest; @@ -11,6 +10,8 @@ import com.example.solidconnection.mentor.domain.MentorApplication; import com.example.solidconnection.mentor.domain.MentorApplicationStatus; import com.example.solidconnection.mentor.repository.MentorApplicationRepository; +import com.example.solidconnection.university.domain.University; +import com.example.solidconnection.university.repository.UniversityRepository; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -22,6 +23,7 @@ public class AdminMentorApplicationService { private final MentorApplicationRepository mentorApplicationRepository; + private final UniversityRepository universityRepository; @Transactional(readOnly = true) public Page searchMentorApplications( @@ -36,15 +38,14 @@ public void approveMentorApplication(Long mentorApplicationId) { MentorApplication mentorApplication = mentorApplicationRepository.findById(mentorApplicationId) .orElseThrow(() -> new CustomException(MENTOR_APPLICATION_NOT_FOUND)); - if(mentorApplication.getUniversityId() == null){ - throw new CustomException(MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED); - } - mentorApplication.approve(); } @Transactional - public void rejectMentorApplication(long mentorApplicationId, MentorApplicationRejectRequest request) { + public void rejectMentorApplication( + long mentorApplicationId, + MentorApplicationRejectRequest request + ) { MentorApplication mentorApplication = mentorApplicationRepository.findById(mentorApplicationId) .orElseThrow(() -> new CustomException(MENTOR_APPLICATION_NOT_FOUND)); @@ -63,4 +64,19 @@ public MentorApplicationCountResponse getMentorApplicationCount() { rejectedCount ); } + + @Transactional + public void assignUniversity( + Long mentorApplicationId, + Long universityId + ) { + MentorApplication mentorApplication = mentorApplicationRepository.findById(mentorApplicationId) + .orElseThrow(() -> new CustomException(MENTOR_APPLICATION_NOT_FOUND)); + + mentorApplication.validateCanAssignUniversity(); + + University university = universityRepository.getUniversityById(universityId); + + mentorApplication.assignUniversity(university.getId()); + } } diff --git a/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java b/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java index a1837d30..0ca6ef61 100644 --- a/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java +++ b/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java @@ -131,6 +131,7 @@ public enum ErrorCode { MENTOR_ALREADY_EXISTS(HttpStatus.BAD_REQUEST.value(), "이미 존재하는 멘토입니다."), MENTOR_APPLICATION_ALREADY_CONFIRMED(HttpStatus.BAD_REQUEST.value(), "이미 승인 또는 거절된 멘토 승격 요청 입니다."), MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED(HttpStatus.BAD_REQUEST.value(), "승인하려는 멘토 신청에 대학교가 선택되지 않았습니다."), + MENTOR_APPLICATION_NOT_OTHER_STATUS(HttpStatus.BAD_REQUEST.value(), "대학 선택 타입이 OTHER이 아닌 멘토 지원서 입니다."), // socket UNAUTHORIZED_SUBSCRIBE(HttpStatus.FORBIDDEN.value(), "구독 권한이 없습니다."), diff --git a/src/main/java/com/example/solidconnection/mentor/domain/MentorApplication.java b/src/main/java/com/example/solidconnection/mentor/domain/MentorApplication.java index 502ae123..fe4f2ccb 100644 --- a/src/main/java/com/example/solidconnection/mentor/domain/MentorApplication.java +++ b/src/main/java/com/example/solidconnection/mentor/domain/MentorApplication.java @@ -1,6 +1,8 @@ package com.example.solidconnection.mentor.domain; import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_ALREADY_CONFIRMED; +import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_NOT_OTHER_STATUS; +import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED; import static java.time.ZoneOffset.UTC; import static java.time.temporal.ChronoUnit.MICROS; @@ -122,18 +124,39 @@ private void validateExchangeStatus(ExchangeStatus exchangeStatus) { } public void approve(){ - if(this.mentorApplicationStatus != MentorApplicationStatus.PENDING) { - throw new CustomException(MENTOR_APPLICATION_ALREADY_CONFIRMED); - } + validatePending(); + validateCanApprove(); this.mentorApplicationStatus = MentorApplicationStatus.APPROVED; this.approvedAt = ZonedDateTime.now(UTC).truncatedTo(MICROS); } + private void validateCanApprove(){ + if(this.universitySelectType != UniversitySelectType.CATALOG){ + throw new CustomException(MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED); + } + } + public void reject(String rejectedReason){ + validatePending(); + this.mentorApplicationStatus = MentorApplicationStatus.REJECTED; + this.rejectedReason = rejectedReason; + } + + public void assignUniversity(long universityId) { + this.universityId = universityId; + this.universitySelectType = UniversitySelectType.CATALOG; + } + + public void validateCanAssignUniversity(){ + validatePending(); + if(this.universitySelectType != UniversitySelectType.OTHER){ + throw new CustomException(MENTOR_APPLICATION_NOT_OTHER_STATUS); + } + } + + private void validatePending(){ if(this.mentorApplicationStatus != MentorApplicationStatus.PENDING) { throw new CustomException(MENTOR_APPLICATION_ALREADY_CONFIRMED); } - this.mentorApplicationStatus = MentorApplicationStatus.REJECTED; - this.rejectedReason = rejectedReason; } } diff --git a/src/main/java/com/example/solidconnection/mentor/repository/custom/MentorApplicationFilterRepositoryImpl.java b/src/main/java/com/example/solidconnection/mentor/repository/custom/MentorApplicationFilterRepositoryImpl.java index 788bda8a..38dc0b6e 100644 --- a/src/main/java/com/example/solidconnection/mentor/repository/custom/MentorApplicationFilterRepositoryImpl.java +++ b/src/main/java/com/example/solidconnection/mentor/repository/custom/MentorApplicationFilterRepositoryImpl.java @@ -12,6 +12,7 @@ import com.example.solidconnection.admin.dto.MentorApplicationSearchResponse; import com.example.solidconnection.admin.dto.SiteUserResponse; import com.example.solidconnection.mentor.domain.MentorApplicationStatus; +import com.example.solidconnection.mentor.domain.UniversitySelectType; import com.querydsl.core.types.ConstructorExpression; import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.BooleanExpression; @@ -48,6 +49,7 @@ public class MentorApplicationFilterRepositoryImpl implements MentorApplicationF region.koreanName, country.koreanName, university.koreanName, + mentorApplication.universitySelectType, mentorApplication.mentorProofUrl, mentorApplication.mentorApplicationStatus, mentorApplication.rejectedReason, @@ -81,7 +83,8 @@ public Page searchMentorApplications(MentorAppl .where( verifyMentorStatusEq(condition.mentorApplicationStatus()), keywordContains(condition.keyword()), - createdAtEq(condition.createdAt()) + createdAtEq(condition.createdAt()), + universitySelectTypeEq(condition.universitySelectType()) ) .orderBy(mentorApplication.createdAt.desc()) .offset(pageable.getOffset()) @@ -110,7 +113,8 @@ private JPAQuery createCountQuery(MentorApplicationSearchCondition conditi return query.where( verifyMentorStatusEq(condition.mentorApplicationStatus()), keywordContains(condition.keyword()), - createdAtEq(condition.createdAt()) + createdAtEq(condition.createdAt()), + universitySelectTypeEq(condition.universitySelectType()) ); } @@ -142,4 +146,8 @@ private BooleanExpression createdAtEq(LocalDate createdAt) { endOfDay.atZone(SYSTEM_ZONE_ID) ); } + + private BooleanExpression universitySelectTypeEq(UniversitySelectType universitySelectType) { + return universitySelectType != null ? mentorApplication.universitySelectType.eq(universitySelectType) : null; + } } diff --git a/src/test/java/com/example/solidconnection/admin/service/AdminMentorApplicationServiceTest.java b/src/test/java/com/example/solidconnection/admin/service/AdminMentorApplicationServiceTest.java index dd844d86..ae40cb5d 100644 --- a/src/test/java/com/example/solidconnection/admin/service/AdminMentorApplicationServiceTest.java +++ b/src/test/java/com/example/solidconnection/admin/service/AdminMentorApplicationServiceTest.java @@ -2,7 +2,9 @@ import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_ALREADY_CONFIRMED; import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_NOT_FOUND; +import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_NOT_OTHER_STATUS; import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_APPLICATION_UNIVERSITY_NOT_SELECTED; +import static com.example.solidconnection.common.exception.ErrorCode.UNIVERSITY_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; import static org.junit.jupiter.api.Assertions.assertAll; @@ -58,6 +60,8 @@ class AdminMentorApplicationServiceTest { private MentorApplication mentorApplication4; private MentorApplication mentorApplication5; private MentorApplication mentorApplication6; + private MentorApplication mentorApplication7; + private MentorApplication mentorApplication8; @BeforeEach void setUp() { @@ -67,6 +71,8 @@ void setUp() { SiteUser user4 = siteUserFixture.사용자(4, "test4"); SiteUser user5 = siteUserFixture.사용자(5, "test5"); SiteUser user6 = siteUserFixture.사용자(6, "test6"); + SiteUser user7 = siteUserFixture.사용자(7, "test7"); + SiteUser user8 = siteUserFixture.사용자(8, "test8"); University university1 = universityFixture.메이지_대학(); University university2 = universityFixture.괌_대학(); University university3 = universityFixture.그라츠_대학(); @@ -76,6 +82,8 @@ void setUp() { mentorApplication4 = mentorApplicationFixture.승인된_멘토신청(user4.getId(), UniversitySelectType.CATALOG, university3.getId()); mentorApplication5 = mentorApplicationFixture.대기중_멘토신청(user5.getId(), UniversitySelectType.CATALOG, university1.getId()); mentorApplication6 = mentorApplicationFixture.거절된_멘토신청(user6.getId(), UniversitySelectType.CATALOG, university2.getId()); + mentorApplication7 = mentorApplicationFixture.대기중_멘토신청(user7.getId(), UniversitySelectType.OTHER, null); + mentorApplication8 = mentorApplicationFixture.거절된_멘토신청(user8.getId(), UniversitySelectType.OTHER, null); } @Nested @@ -84,30 +92,32 @@ class 멘토_승격_지원서_목록_조회 { @Test void 멘토_승격_상태를_조건으로_페이징하여_조회한다() { // given - MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(MentorApplicationStatus.PENDING,null, null); + MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(MentorApplicationStatus.PENDING,null, null, null); Pageable pageable = PageRequest.of(0, 10); - List expectedMentorApplications = List.of(mentorApplication2, mentorApplication5); + List expectedMentorApplications = List.of(mentorApplication2, mentorApplication5, mentorApplication7); // when Page response = adminMentorApplicationService.searchMentorApplications(condition, pageable); // then - assertThat(response.getContent()).hasSize(expectedMentorApplications.size()); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().id()) - .containsOnly(expectedMentorApplications.stream() - .map(MentorApplication::getId) - .toArray(Long[]::new)); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().mentorApplicationStatus()) - .containsOnly(MentorApplicationStatus.PENDING); + assertAll( + () -> assertThat(response.getContent()).hasSize(expectedMentorApplications.size()), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().id()) + .containsOnly(expectedMentorApplications.stream() + .map(MentorApplication::getId) + .toArray(Long[]::new)), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().mentorApplicationStatus()) + .containsOnly(MentorApplicationStatus.PENDING) + ); } @Test void 닉네임_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){ // given String nickname = "test1"; - MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, nickname, null); + MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, nickname, null, null); Pageable pageable = PageRequest.of(0, 10); List expectedMentorApplications = List.of(mentorApplication1); @@ -115,22 +125,24 @@ class 멘토_승격_지원서_목록_조회 { Page response = adminMentorApplicationService.searchMentorApplications(condition, pageable); // then - assertThat(response.getContent()).hasSize(expectedMentorApplications.size()); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().id()) - .containsOnly(expectedMentorApplications.stream() - .map(MentorApplication::getId) - .toArray(Long[]::new)); - assertThat(response.getContent()) - .extracting(content -> content.siteUserResponse().nickname()) - .containsOnly(nickname); + assertAll( + () -> assertThat(response.getContent()).hasSize(expectedMentorApplications.size()), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().id()) + .containsOnly(expectedMentorApplications.stream() + .map(MentorApplication::getId) + .toArray(Long[]::new)), + () -> assertThat(response.getContent()) + .extracting(content -> content.siteUserResponse().nickname()) + .containsOnly(nickname) + ); } @Test void 대학명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){ // given String universityKoreanName = "메이지 대학"; - MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, universityKoreanName, null); + MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, universityKoreanName, null, null); Pageable pageable = PageRequest.of(0, 10); List expectedMentorApplications = List.of(mentorApplication1, mentorApplication5); @@ -138,22 +150,24 @@ class 멘토_승격_지원서_목록_조회 { Page response = adminMentorApplicationService.searchMentorApplications(condition, pageable); // then - assertThat(response.getContent()).hasSize(expectedMentorApplications.size()); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().id()) - .containsOnly(expectedMentorApplications.stream() - .map(MentorApplication::getId) - .toArray(Long[]::new)); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().university()) - .containsOnly(universityKoreanName); + assertAll( + () -> assertThat(response.getContent()).hasSize(expectedMentorApplications.size()), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().id()) + .containsOnly(expectedMentorApplications.stream() + .map(MentorApplication::getId) + .toArray(Long[]::new)), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().university()) + .containsOnly(universityKoreanName) + ); } @Test void 지역명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){ // given String regionKoreanName = "유럽"; - MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, regionKoreanName, null); + MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, regionKoreanName, null, null); Pageable pageable = PageRequest.of(0, 10); List expectedMentorApplications = List.of(mentorApplication3, mentorApplication4); @@ -161,22 +175,24 @@ class 멘토_승격_지원서_목록_조회 { Page response = adminMentorApplicationService.searchMentorApplications(condition, pageable); // then - assertThat(response.getContent()).hasSize(expectedMentorApplications.size()); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().id()) - .containsOnly(expectedMentorApplications.stream() - .map(MentorApplication::getId) - .toArray(Long[]::new)); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().region()) - .containsOnly(regionKoreanName); + assertAll( + () -> assertThat(response.getContent()).hasSize(expectedMentorApplications.size()), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().id()) + .containsOnly(expectedMentorApplications.stream() + .map(MentorApplication::getId) + .toArray(Long[]::new)), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().region()) + .containsOnly(regionKoreanName) + ); } @Test void 나라명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){ // given String countryKoreanName = "오스트리아"; - MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, countryKoreanName, null); + MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, countryKoreanName, null,null); Pageable pageable = PageRequest.of(0, 10); List expectedMentorApplications = List.of(mentorApplication3, mentorApplication4); @@ -184,22 +200,75 @@ class 멘토_승격_지원서_목록_조회 { Page response = adminMentorApplicationService.searchMentorApplications(condition, pageable); // then - assertThat(response.getContent()).hasSize(expectedMentorApplications.size()); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().id()) - .containsOnly(expectedMentorApplications.stream() - .map(MentorApplication::getId) - .toArray(Long[]::new)); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().country()) - .containsOnly(countryKoreanName); + assertAll( + () -> assertThat(response.getContent()).hasSize(expectedMentorApplications.size()), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().id()) + .containsOnly(expectedMentorApplications.stream() + .map(MentorApplication::getId) + .toArray(Long[]::new)), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().country()) + .containsOnly(countryKoreanName) + ); + } + + @Test + void CATALOG_타입의_멘토_지원서만_조회한다() { + // given + MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, null, null, UniversitySelectType.CATALOG); + Pageable pageable = PageRequest.of(0, 10); + List expectedMentorApplications = List.of( + mentorApplication1, mentorApplication2, mentorApplication3, + mentorApplication4, mentorApplication5, mentorApplication6 + ); + + // when + Page response = adminMentorApplicationService.searchMentorApplications(condition, pageable); + + // then + assertAll( + () -> assertThat(response.getContent()).hasSize(expectedMentorApplications.size()), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().id()) + .containsOnly(expectedMentorApplications.stream() + .map(MentorApplication::getId) + .toArray(Long[]::new)), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().universitySelectType()) + .containsOnly(UniversitySelectType.CATALOG) + ); + } + + @Test + void OTHER_타입의_멘토_지원서만_조회한다() { + // given + MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, null, null, UniversitySelectType.OTHER); + Pageable pageable = PageRequest.of(0, 10); + List expectedMentorApplications = List.of(mentorApplication7, mentorApplication8); + + // when + Page response = adminMentorApplicationService.searchMentorApplications(condition, pageable); + + // then + assertAll( + () -> assertThat(response.getContent()).hasSize(expectedMentorApplications.size()), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().id()) + .containsOnly(expectedMentorApplications.stream() + .map(MentorApplication::getId) + .toArray(Long[]::new)), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().universitySelectType()) + .containsOnly(UniversitySelectType.OTHER) + ); } @Test void 모든_조건으로_페이징하여_조회한다() { // given String regionKoreanName = "영미권"; - MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(MentorApplicationStatus.PENDING, regionKoreanName, LocalDate.now()); + MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(MentorApplicationStatus.PENDING, regionKoreanName, LocalDate.now(), UniversitySelectType.CATALOG); Pageable pageable = PageRequest.of(0, 10); List expectedMentorApplications = List.of(mentorApplication2); @@ -207,18 +276,20 @@ class 멘토_승격_지원서_목록_조회 { Page response = adminMentorApplicationService.searchMentorApplications(condition, pageable); // then - assertThat(response.getContent()).hasSize(expectedMentorApplications.size()); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().id()) - .containsOnly(expectedMentorApplications.stream() - .map(MentorApplication::getId) - .toArray(Long[]::new)); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().mentorApplicationStatus()) - .containsOnly(MentorApplicationStatus.PENDING); - assertThat(response.getContent()) - .extracting(content -> content.mentorApplicationResponse().region()) - .containsOnly(regionKoreanName); + assertAll( + () -> assertThat(response.getContent()).hasSize(expectedMentorApplications.size()), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().id()) + .containsOnly(expectedMentorApplications.stream() + .map(MentorApplication::getId) + .toArray(Long[]::new)), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().mentorApplicationStatus()) + .containsOnly(MentorApplicationStatus.PENDING), + () -> assertThat(response.getContent()) + .extracting(content -> content.mentorApplicationResponse().region()) + .containsOnly(regionKoreanName) + ); } } @@ -235,8 +306,10 @@ class 멘토_승격_지원서_승인{ // then MentorApplication result = mentorApplicationRepository.findById(mentorApplication2.getId()).get(); - assertThat(result.getMentorApplicationStatus()).isEqualTo(MentorApplicationStatus.APPROVED); - assertThat(result.getApprovedAt()).isNotNull(); + assertAll( + () -> assertThat(result.getMentorApplicationStatus()).isEqualTo(MentorApplicationStatus.APPROVED), + () -> assertThat(result.getApprovedAt()).isNotNull() + ); } @Test @@ -299,8 +372,10 @@ class 멘토_승격_지원서_거절{ // then MentorApplication result = mentorApplicationRepository.findById(mentorApplication2.getId()).get(); - assertThat(result.getMentorApplicationStatus()).isEqualTo(MentorApplicationStatus.REJECTED); - assertThat(result.getRejectedReason()).isEqualTo(request.rejectedReason()); + assertAll( + () -> assertThat(result.getMentorApplicationStatus()).isEqualTo(MentorApplicationStatus.REJECTED), + () -> assertThat(result.getRejectedReason()).isEqualTo(request.rejectedReason()) + ); } @Test @@ -347,8 +422,8 @@ class 멘토_지원서_상태별_개수_조회 { void 상태별_멘토_지원서_개수를_조회한다() { // given List expectedApprovedCount = List.of(mentorApplication1, mentorApplication4); - List expectedPendingCount = List.of(mentorApplication2, mentorApplication5); - List expectedRejectedCount = List.of(mentorApplication3, mentorApplication6); + List expectedPendingCount = List.of(mentorApplication2, mentorApplication5, mentorApplication7); + List expectedRejectedCount = List.of(mentorApplication3, mentorApplication6, mentorApplication8); // when MentorApplicationCountResponse response = adminMentorApplicationService.getMentorApplicationCount(); @@ -377,4 +452,61 @@ class 멘토_지원서_상태별_개수_조회 { ); } } + + @Nested + class 멘토_지원서에_대학_매핑 { + + @Test + void OTHER_타입의_멘토_지원서에_대학을_매핑하면_대학이_할당되고_타입이_CATALOG로_변경된다() { + // given + long otherTypeMentorApplicationId = mentorApplication7.getId(); + University university = universityFixture.메이지_대학(); + + // when + adminMentorApplicationService.assignUniversity(otherTypeMentorApplicationId, university.getId()); + + // then + MentorApplication result = mentorApplicationRepository.findById(otherTypeMentorApplicationId).get(); + assertAll( + () -> assertThat(result.getUniversityId()).isEqualTo(university.getId()), + () -> assertThat(result.getUniversitySelectType()).isEqualTo(UniversitySelectType.CATALOG) + ); + } + + @Test + void 존재하지_않는_멘토_지원서에_대학을_매핑하면_예외_응답을_반환한다() { + // given + long nonExistentId = 99999L; + University university = universityFixture.메이지_대학(); + + // when & then + assertThatCode(() -> adminMentorApplicationService.assignUniversity(nonExistentId, university.getId())) + .isInstanceOf(CustomException.class) + .hasMessage(MENTOR_APPLICATION_NOT_FOUND.getMessage()); + } + + @Test + void CATALOG_타입의_멘토_지원서에_대학을_매핑하면_예외_응답을_반환한다() { + // given + long catalogTypeMentorApplicationId = mentorApplication2.getId(); + University university = universityFixture.메이지_대학(); + + // when & then + assertThatCode(() -> adminMentorApplicationService.assignUniversity(catalogTypeMentorApplicationId, university.getId())) + .isInstanceOf(CustomException.class) + .hasMessage(MENTOR_APPLICATION_NOT_OTHER_STATUS.getMessage()); + } + + @Test + void 존재하지_않는_대학을_매핑하면_예외_응답을_반환한다() { + // given + long otherTypeMentorApplicationId = mentorApplication7.getId(); + long nonExistentUniversityId = 99999L; + + // when & then + assertThatCode(() -> adminMentorApplicationService.assignUniversity(otherTypeMentorApplicationId, nonExistentUniversityId)) + .isInstanceOf(CustomException.class) + .hasMessage(UNIVERSITY_NOT_FOUND.getMessage()); + } + } }