-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] - [Company] 기업 쿼리 개선 중입니다.
[Feature] - [Company] 기업 쿼리 개선 중입니다.
- Loading branch information
Showing
6 changed files
with
38 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/coverflow/global/util/RepositoryUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.coverflow.global.util; | ||
|
||
import com.querydsl.core.types.Order; | ||
import com.querydsl.core.types.OrderSpecifier; | ||
import com.querydsl.core.types.dsl.EntityPathBase; | ||
import com.querydsl.core.types.dsl.PathBuilder; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
|
||
public class RepositoryUtil { | ||
|
||
private RepositoryUtil() { | ||
} | ||
|
||
public static <T> OrderSpecifier[] makeOrderSpecifiers(final EntityPathBase<T> qClass, final Pageable pageable) { | ||
return pageable.getSort() | ||
.stream() | ||
.map(sort -> toOrderSpecifier(qClass, sort)) | ||
.toList().toArray(OrderSpecifier[]::new); | ||
} | ||
|
||
private static <T> OrderSpecifier toOrderSpecifier(final EntityPathBase<T> qClass, final Sort.Order sortOrder) { | ||
final Order orderMethod = toOrder(sortOrder); | ||
final PathBuilder<T> pathBuilder = new PathBuilder<>(qClass.getType(), qClass.getMetadata()); | ||
return new OrderSpecifier(orderMethod, pathBuilder.get(sortOrder.getProperty())); | ||
} | ||
|
||
private static Order toOrder(final Sort.Order sortOrder) { | ||
if (sortOrder.isAscending()) { | ||
return Order.ASC; | ||
} | ||
return Order.DESC; | ||
} | ||
} |