Skip to content

Commit

Permalink
RAC-403 fix : 선배 조회시 멘토링 횟수 정렬 우선으로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ywj9811 committed Jul 2, 2024
1 parent c23f662 commit 6243e41
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SeniorDslRepositoryImpl implements SeniorDslRepository{

@Override
public Page<Senior> findAllBySearchSenior(String search, String sort, Pageable pageable) {
List<Tuple> results = queryFactory.select(senior.seniorId, senior.user.nickName, senior.hit)
List<Tuple> results = queryFactory.select(senior.seniorId, senior.user.nickName, senior.hit, senior.mentoringHit)
.from(senior)
.distinct()
.leftJoin(senior.user, user)
Expand All @@ -46,7 +46,8 @@ public Page<Senior> findAllBySearchSenior(String search, String sort, Pageable p
.or(senior.user.nickName.like("%" + search + "%")),
senior.user.isDelete.eq(FALSE)
)
.orderBy(orderSpecifier(sort))
.orderBy(mentoringOrderSpecifier(sort))
.orderBy(hitOrderSpecifier(sort))
.orderBy(senior.user.nickName.asc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
Expand All @@ -62,7 +63,8 @@ public Page<Senior> findAllBySearchSenior(String search, String sort, Pageable p
.toList()))
.leftJoin(senior.user, user)
.fetchJoin()
.orderBy(orderSpecifier(sort))
.orderBy(mentoringOrderSpecifier(sort))
.orderBy(hitOrderSpecifier(sort))
.orderBy(senior.user.nickName.asc())
.fetch();

Expand All @@ -81,17 +83,26 @@ public Page<Senior> findAllBySearchSenior(String search, String sort, Pageable p
return new PageImpl<>(seniors, pageable, total);
}

private OrderSpecifier<?> orderSpecifier(String sort) {
private OrderSpecifier<?> hitOrderSpecifier(String sort) {
if (sort == null)
return new OrderSpecifier<>(DESC, senior.hit);
if (sort.equals("low"))
return new OrderSpecifier<>(ASC, senior.hit);
return new OrderSpecifier<>(DESC, senior.hit);
}

private OrderSpecifier<?> mentoringOrderSpecifier(String sort) {
if (sort == null)
return new OrderSpecifier<>(DESC, senior.mentoringHit);
if (sort.equals("low"))
return new OrderSpecifier<>(ASC, senior.mentoringHit);
return new OrderSpecifier<>(DESC, senior.mentoringHit);
}


@Override
public Page<Senior> findAllByFieldSenior(String field, String postgradu, Pageable pageable) {
List<Tuple> results = queryFactory.select(senior.seniorId, senior.user.nickName, senior.hit)
List<Tuple> results = queryFactory.select(senior.seniorId, senior.user.nickName, senior.hit, senior.mentoringHit)
.from(senior)
.distinct()
.leftJoin(senior.user, user)
Expand All @@ -100,6 +111,7 @@ public Page<Senior> findAllByFieldSenior(String field, String postgradu, Pageabl
postgraduSpecifier(postgradu),
senior.user.isDelete.eq(FALSE)
)
.orderBy(senior.mentoringHit.desc())
.orderBy(senior.hit.desc())
.orderBy(senior.user.nickName.asc())
.offset(pageable.getOffset())
Expand All @@ -116,6 +128,7 @@ public Page<Senior> findAllByFieldSenior(String field, String postgradu, Pageabl
.toList()))
.leftJoin(senior.user, user)
.fetchJoin()
.orderBy(senior.mentoringHit.desc())
.orderBy(senior.hit.desc())
.orderBy(senior.user.nickName.asc())
.fetch();
Expand Down

0 comments on commit 6243e41

Please sign in to comment.