Skip to content

Commit

Permalink
refactor: develop 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
kyukong committed May 28, 2024
1 parent 663c555 commit f8d8409
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 55 deletions.
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);
}

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

0 comments on commit f8d8409

Please sign in to comment.