Skip to content

Commit

Permalink
✨ feat: 등급 낮은순 정렬 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
tmddus2 committed Aug 28, 2024
1 parent 756d410 commit ed6b698
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public SuccessResponse<FilterListDto> getFilters(
{@ExampleObject(name = "최신순", summary = "최신순 정렬", value = "latest"),
@ExampleObject(name = "오래된순", summary = "오래된순 정렬", value = "earliest"),
@ExampleObject(name = "퓨어지수 높은순", summary = "퓨어지수 높은순 정렬", value = "popular"),
@ExampleObject(name = "이름순", summary = "이름순 정렬", value = "name")}) String sortedBy,
@ExampleObject(name = "이름순", summary = "이름순 정렬", value = "name"),
@ExampleObject(name = "등급 낮은순", summary = "등급 낮은순 정렬", value = "membership")}) String sortedBy,
@RequestParam(value = "page") int page,
@RequestParam(value = "size") int size
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public interface CustomFilterRepository {
Page<Object[]> findAllWithReviewSorting(OS os, Tag tag, Long photographerId, Pageable pageable);
Page<Object[]> findAllWithViewsSorting(OS os, Long photographerId, Pageable pageable);
Page<Filter> findAllWithNameSorting(OS os, Tag tag, Long photographerId, Pageable pageable);
Page<Filter> findAllWithMembershipSorting(OS os, Tag tag, Long photographerId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ public Page<Filter> findAllWithNameSorting(OS os, Tag tag, Long photographerId,
return new PageImpl<>(results, pageable, total);
}

@Override
public Page<Filter> findAllWithMembershipSorting(OS os, Tag tag, Long photographerId, Pageable pageable) {
BooleanBuilder builder = this.createBuilder(os, tag, photographerId);

List<Filter> results = jpaQueryFactory
.selectFrom(filter)
.where(builder)
.orderBy(filter.membership.asc(), filter.name.asc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

long total = jpaQueryFactory
.select(filter.count())
.from(filter)
.where(builder).fetchOne();

return new PageImpl<>(results, pageable, total);
}

private BooleanBuilder createBuilder(OS os, Tag tag, Long photographerId) {
BooleanBuilder builder = new BooleanBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ public FilterListDto getFilters(Long id, int page, int size, OS os, Tag tag, Str
isLike((filter).getId(), id),
filterLikeRepository.getLikes(filter),
checkAccess(user.getMembership(), (filter).getMembership()))).toList();
} else if (sortedBy.equals("membership")) {
Page<Filter> filterByName = filterRepository.findAllWithMembershipSorting(os, tag, photographerId, pageRequest);
isLast = filterByName.isLast();
totalPage = filterByName.getTotalPages();
totalElement = filterByName.getTotalElements();
filterDtos = filterByName.getContent().stream().map(filter ->
FilterDto.of(
filter,
isLike((filter).getId(), id),
filterLikeRepository.getLikes(filter),
checkAccess(user.getMembership(), (filter).getMembership()))).toList();
} else {
pageRequest = PageRequest.of(page, size, Sort.by("createdAt").descending()); // 정렬 없을 때는 최신 순
Page<Filter> filterByLatest = filterRepository.findAllByOs(os, tag, photographerId, pageRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public SuccessResponse<FilterListDto> getFiltersByPhotographer(
{@ExampleObject(name = "최신순", summary = "최신순 정렬", value = "latest"),
@ExampleObject(name = "퓨어지수 높은순", summary = "퓨어지수 높은순 정렬", value = "pure"),
@ExampleObject(name = "조회순", summary = "조회순 정렬", value = "views"),
@ExampleObject(name = "이름순", summary = "이름순 정렬", value = "name")}) String sortedBy,
@ExampleObject(name = "이름순", summary = "이름순 정렬", value = "name"),
@ExampleObject(name = "등급 낮은순", summary = "등급 낮은순 정렬", value = "membership")}) String sortedBy,
@RequestParam(value = "os", required = true) @Parameter(description = "휴대폰 os",
examples = {@ExampleObject(value = "AOS"), @ExampleObject(value = "iOS")}) OS os,
@RequestParam(value = "page") int page,
Expand Down

0 comments on commit ed6b698

Please sign in to comment.