Skip to content

Commit

Permalink
Merge pull request #291 from Gongjakso/feature/contest
Browse files Browse the repository at this point in the history
fix : query where 수정
  • Loading branch information
sycuuui authored Nov 13, 2024
2 parents e054397 + ea1177b commit 97282b8
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@ public ContestRepositoryImpl(EntityManager em) {

@Override
public Page<Contest> searchList(String word, String sortAt, Pageable pageable) {
BooleanExpression filterCondition = wordEq(word);

if ("ACTIVE".equals(sortAt)) {
filterCondition = (filterCondition == null ? contest.finishedAt.goe(LocalDate.now())
: filterCondition.and(contest.finishedAt.goe(LocalDate.now())));
}

List<Contest> contestList = queryFactory
.selectDistinct(contest)
.from(contest)
.where(wordEq(word))
.where(filterCondition)
.orderBy(arg(sortAt))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
long total = queryFactory
.select(contest.count())
.from(contest)
.where(wordEq(word)) // Full-Text Search 조건 추가
.where(filterCondition) // Full-Text Search 조건 추가
.fetchOne();

return new PageImpl<>(contestList,pageable,total);
Expand All @@ -45,8 +52,8 @@ private OrderSpecifier<?> arg(String sortAt){
if("VIEW".equals(sortAt)){
return contest.view.desc();//조회순
}
if("ACTIVE".equals(sortAt)){
return contest.finishedAt.after(LocalDate.now()).desc(); //활동 중인 공모전
if ("ACTIVE".equals(sortAt)) {
return contest.finishedAt.asc(); // 종료일 기준 오름차순
}
return contest.createdAt.desc(); //최신순
}
Expand Down

0 comments on commit 97282b8

Please sign in to comment.