diff --git a/out-adapter-persistence-jpa/src/main/java/gohigher/application/entity/ApplicationRepositoryCustomImpl.java b/out-adapter-persistence-jpa/src/main/java/gohigher/application/entity/ApplicationRepositoryCustomImpl.java index f5a49897..6981a850 100644 --- a/out-adapter-persistence-jpa/src/main/java/gohigher/application/entity/ApplicationRepositoryCustomImpl.java +++ b/out-adapter-persistence-jpa/src/main/java/gohigher/application/entity/ApplicationRepositoryCustomImpl.java @@ -1,7 +1,7 @@ package gohigher.application.entity; -import static gohigher.application.entity.QApplicationJpaEntity.*; -import static gohigher.application.entity.QApplicationProcessJpaEntity.*; +import static gohigher.application.entity.QApplicationJpaEntity.applicationJpaEntity; +import static gohigher.application.entity.QApplicationProcessJpaEntity.applicationProcessJpaEntity; import java.util.List; import java.util.stream.Collectors; @@ -13,6 +13,8 @@ import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.CaseBuilder; +import com.querydsl.core.types.dsl.NumberExpression; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -99,12 +101,23 @@ private BooleanExpression inProcessType(List process) { private OrderSpecifier selectOrderSpecifierAboutFindAll(ApplicationSortingType sortingType) { return switch (sortingType) { case CREATED -> applicationProcessJpaEntity.id.desc(); - case PROCESS_TYPE -> applicationProcessJpaEntity.schedule.asc(); - case REVERSE_PROCESS_TYPE -> applicationProcessJpaEntity.schedule.desc(); + case PROCESS_TYPE -> sortByProcessType().asc(); + case REVERSE_PROCESS_TYPE -> sortByProcessType().desc(); case CLOSING -> applicationProcessJpaEntity.id.asc(); }; } + private NumberExpression sortByProcessType() { + int order = 0; + return new CaseBuilder() + .when(applicationProcessJpaEntity.type.eq(ProcessType.TO_APPLY)).then(order++) + .when(applicationProcessJpaEntity.type.eq(ProcessType.DOCUMENT)).then(order++) + .when(applicationProcessJpaEntity.type.eq(ProcessType.TEST)).then(order++) + .when(applicationProcessJpaEntity.type.eq(ProcessType.INTERVIEW)).then(order++) + .when(applicationProcessJpaEntity.type.eq(ProcessType.COMPLETE)).then(order++) + .otherwise(order); + } + private List convertToApplicationJpaEntity(JPAQuery query) { return query.fetch().stream() .map(processResponse -> diff --git a/out-adapter-persistence-jpa/src/test/java/gohigher/application/entity/ApplicationRepositoryCustomImplTest.java b/out-adapter-persistence-jpa/src/test/java/gohigher/application/entity/ApplicationRepositoryCustomImplTest.java index c23c26e1..80be68b3 100644 --- a/out-adapter-persistence-jpa/src/test/java/gohigher/application/entity/ApplicationRepositoryCustomImplTest.java +++ b/out-adapter-persistence-jpa/src/test/java/gohigher/application/entity/ApplicationRepositoryCustomImplTest.java @@ -53,13 +53,13 @@ class Describe_findAllByUserId { @BeforeEach void setUp() { - Application naverApplication = NAVER_APPLICATION.toDomain(TEST.toDomainWithSchedule(yesterday)); + Application naverApplication = NAVER_APPLICATION.toDomain(DOCUMENT.toDomainWithSchedule(yesterday)); naverApplicationEntity = saveApplicationAndProcesses(userId, naverApplication); Application kakoaApplication = KAKAO_APPLICATION.toDomain(TEST.toDomainWithSchedule(tomorrow)); kakaoApplicationEntity = saveApplicationAndProcesses(userId, kakoaApplication); - Application coupangApplication = COUPANG_APPLICATION.toDomain(TEST.toDomainWithSchedule(today)); + Application coupangApplication = COUPANG_APPLICATION.toDomain(INTERVIEW.toDomainWithSchedule(today)); coupangApplicationEntity = saveApplicationAndProcesses(userId, coupangApplication); } @@ -113,68 +113,64 @@ void it_returns_desc_id() { @Nested class Context_with_scheduled { - @DisplayName("전형일 오름차순으로 정렬되어 조회한다.") - @Test - void it_returns_asc_scheduled() { - ApplicationSortingType sortingType = ApplicationSortingType.PROCESS_TYPE; + @DisplayName("ProcessType 순서로 정렬되어 조회한다.") + @Test + void it_returns_asc_scheduled() { + ApplicationSortingType sortingType = ApplicationSortingType.PROCESS_TYPE; Slice applications = applicationRepositoryCustom.findAllByUserId( userId, pageRequest, sortingType, List.of(), List.of(), null); - assertAll( - () -> assertThat(applications.getNumberOfElements()).isEqualTo(3), - () -> assertThat(applications.getContent().get(0).getId()).isEqualTo( - naverApplicationEntity.getId()), - () -> assertThat(applications.getContent().get(1).getId()).isEqualTo( - coupangApplicationEntity.getId()), - () -> assertThat(applications.getContent().get(2).getId()).isEqualTo(kakaoApplicationEntity.getId()) - ); - } - } + assertAll( + () -> assertThat(applications.getNumberOfElements()).isEqualTo(3), + () -> assertThat(applications.getContent().get(0).getId()).isEqualTo(naverApplicationEntity.getId()), + () -> assertThat(applications.getContent().get(1).getId()).isEqualTo(kakaoApplicationEntity.getId()), + () -> assertThat(applications.getContent().get(2).getId()).isEqualTo(coupangApplicationEntity.getId()) + ); + } + } @DisplayName("정렬 기준이 '전형역순' 일 경우") @Nested class Context_with_re_scheduled { - @DisplayName("전형일 내림차순으로 정렬되어 조회한다.") - @Test - void it_returns_desc_scheduled() { - ApplicationSortingType sortingType = ApplicationSortingType.REVERSE_PROCESS_TYPE; + @DisplayName("ProcessType 역순으로 정렬되어 조회한다.") + @Test + void it_returns_desc_scheduled() { + ApplicationSortingType sortingType = ApplicationSortingType.REVERSE_PROCESS_TYPE; Slice applications = applicationRepositoryCustom.findAllByUserId( userId, pageRequest, sortingType, List.of(), List.of(), null); - assertAll( - () -> assertThat(applications.getNumberOfElements()).isEqualTo(3), - () -> assertThat(applications.getContent().get(0).getId()).isEqualTo( - kakaoApplicationEntity.getId()), - () -> assertThat(applications.getContent().get(1).getId()).isEqualTo( - coupangApplicationEntity.getId()), - () -> assertThat(applications.getContent().get(2).getId()).isEqualTo(naverApplicationEntity.getId()) - ); - } - } - - // @DisplayName("정렬 기준이 '마감임박순' 일 경우") - // @Nested - // class Context_with_closing { - // - // @DisplayName("마감일이 가까운 순으로 정렬되어 조회한다.") - // @Test - // void it_returns_asc_deadline() { - // ApplicationSortingType sortingType = ApplicationSortingType.CLOSING; - // - // Slice applications = applicationRepositoryCustom.findAllByUserId( - // userId, pageRequest, sortingType, null, null, null); - // - // assertAll( - // () -> assertThat(applications.getNumberOfElements()).isEqualTo(3), - // () -> assertThat(applications.getContent().get(0).getCompanyName()).isEqualTo(kakaoApplicationEntity.getCompanyName()), - // () -> assertThat(applications.getContent().get(1).getCompanyName()).isEqualTo(coupangApplicationEntity.getCompanyName()), - // () -> assertThat(applications.getContent().get(2).getCompanyName()).isEqualTo(naverApplicationEntity.getCompanyName()) - // ); - // } - // } + assertAll( + () -> assertThat(applications.getNumberOfElements()).isEqualTo(3), + () -> assertThat(applications.getContent().get(0).getId()).isEqualTo(coupangApplicationEntity.getId()), + () -> assertThat(applications.getContent().get(1).getId()).isEqualTo(kakaoApplicationEntity.getId()), + () -> assertThat(applications.getContent().get(2).getId()).isEqualTo(naverApplicationEntity.getId()) + ); + } + } + + @DisplayName("정렬 기준이 '마감임박순' 일 경우") + @Nested + class Context_with_closing { + + @DisplayName("마감일이 가까운 순으로 정렬되어 조회한다.") + @Test + void it_returns_asc_deadline() { + // ApplicationSortingType sortingType = ApplicationSortingType.CLOSING; + // + // Slice applications = applicationRepositoryCustom.findAllByUserId( + // userId, pageRequest, sortingType, null, null, null); + // + // assertAll( + // () -> assertThat(applications.getNumberOfElements()).isEqualTo(3), + // () -> assertThat(applications.getContent().get(0).getCompanyName()).isEqualTo(kakaoApplicationEntity.getCompanyName()), + // () -> assertThat(applications.getContent().get(1).getCompanyName()).isEqualTo(coupangApplicationEntity.getCompanyName()), + // () -> assertThat(applications.getContent().get(2).getCompanyName()).isEqualTo(naverApplicationEntity.getCompanyName()) + // ); + } + } @DisplayName("전형별로 보기 필터링을 선택하지 않을 경우") @Nested