Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] 나의 지원 현황 모아보기 기능에서 세부 정렬과 필터링 조건 추가 #210

Merged
merged 1 commit into from
Jun 13, 2024
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
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -99,12 +101,23 @@ private BooleanExpression inProcessType(List<ProcessType> 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<Integer> 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);
}
shindong96 marked this conversation as resolved.
Show resolved Hide resolved

private List<ApplicationJpaEntity> convertToApplicationJpaEntity(JPAQuery<ProcessWithApplicationResponse> query) {
return query.fetch().stream()
.map(processResponse ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<ApplicationJpaEntity> 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<ApplicationJpaEntity> 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<ApplicationJpaEntity> 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<ApplicationJpaEntity> 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
Expand Down