From ed6b698657696b891a48f7d97b4206c6c892556b Mon Sep 17 00:00:00 2001 From: tmddus2 Date: Wed, 28 Aug 2024 20:42:27 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=EB=93=B1=EA=B8=89=20?= =?UTF-8?q?=EB=82=AE=EC=9D=80=EC=88=9C=20=EC=A0=95=EB=A0=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FilterControllerDocs.java | 3 ++- .../repository/CustomFilterRepository.java | 1 + .../CustomFilterRepositoryImpl.java | 20 +++++++++++++++++++ .../domain/filter/service/FilterService.java | 11 ++++++++++ .../PhotographerControllerDocs.java | 3 ++- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/purithm/src/main/java/com/example/purithm/domain/filter/controller/FilterControllerDocs.java b/purithm/src/main/java/com/example/purithm/domain/filter/controller/FilterControllerDocs.java index 872647d..0332a4b 100644 --- a/purithm/src/main/java/com/example/purithm/domain/filter/controller/FilterControllerDocs.java +++ b/purithm/src/main/java/com/example/purithm/domain/filter/controller/FilterControllerDocs.java @@ -30,7 +30,8 @@ public SuccessResponse 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 ); diff --git a/purithm/src/main/java/com/example/purithm/domain/filter/repository/CustomFilterRepository.java b/purithm/src/main/java/com/example/purithm/domain/filter/repository/CustomFilterRepository.java index b9c95ab..28e8af9 100644 --- a/purithm/src/main/java/com/example/purithm/domain/filter/repository/CustomFilterRepository.java +++ b/purithm/src/main/java/com/example/purithm/domain/filter/repository/CustomFilterRepository.java @@ -13,4 +13,5 @@ public interface CustomFilterRepository { Page findAllWithReviewSorting(OS os, Tag tag, Long photographerId, Pageable pageable); Page findAllWithViewsSorting(OS os, Long photographerId, Pageable pageable); Page findAllWithNameSorting(OS os, Tag tag, Long photographerId, Pageable pageable); + Page findAllWithMembershipSorting(OS os, Tag tag, Long photographerId, Pageable pageable); } diff --git a/purithm/src/main/java/com/example/purithm/domain/filter/repository/CustomFilterRepositoryImpl.java b/purithm/src/main/java/com/example/purithm/domain/filter/repository/CustomFilterRepositoryImpl.java index 555bf81..7d64e3e 100644 --- a/purithm/src/main/java/com/example/purithm/domain/filter/repository/CustomFilterRepositoryImpl.java +++ b/purithm/src/main/java/com/example/purithm/domain/filter/repository/CustomFilterRepositoryImpl.java @@ -155,6 +155,26 @@ public Page findAllWithNameSorting(OS os, Tag tag, Long photographerId, return new PageImpl<>(results, pageable, total); } + @Override + public Page findAllWithMembershipSorting(OS os, Tag tag, Long photographerId, Pageable pageable) { + BooleanBuilder builder = this.createBuilder(os, tag, photographerId); + + List 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(); diff --git a/purithm/src/main/java/com/example/purithm/domain/filter/service/FilterService.java b/purithm/src/main/java/com/example/purithm/domain/filter/service/FilterService.java index 05cc245..5d2d295 100644 --- a/purithm/src/main/java/com/example/purithm/domain/filter/service/FilterService.java +++ b/purithm/src/main/java/com/example/purithm/domain/filter/service/FilterService.java @@ -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 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 filterByLatest = filterRepository.findAllByOs(os, tag, photographerId, pageRequest); diff --git a/purithm/src/main/java/com/example/purithm/domain/photographer/controller/PhotographerControllerDocs.java b/purithm/src/main/java/com/example/purithm/domain/photographer/controller/PhotographerControllerDocs.java index fb0e91c..e05dec9 100644 --- a/purithm/src/main/java/com/example/purithm/domain/photographer/controller/PhotographerControllerDocs.java +++ b/purithm/src/main/java/com/example/purithm/domain/photographer/controller/PhotographerControllerDocs.java @@ -39,7 +39,8 @@ public SuccessResponse 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,