From 25484b2b447fee949c4726efd5b83042b9ace2c9 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Wed, 3 Jan 2024 21:26:09 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[feat]=20#17=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20api=20contro?= =?UTF-8?q?ller=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/controller/PostController.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java index 6247135..f64fdfd 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java +++ b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java @@ -15,11 +15,11 @@ public class PostController { private final PostService postService; - @GetMapping("/search") - public ResponseEntity> searchTextPost(@UserId final Long userId, - @RequestParam final String text, - final Pageable pageable) { - final PostSearchResponseDto responseDto = postService.searchTextPost(userId, text, pageable); + @GetMapping + public ResponseEntity> getAllPosts(@UserId final Long userId, + @RequestParam final String type, + final Pageable pageable){ + final PostSearchResponseDto responseDto = postService.getAllPosts(userId, type, pageable); return SuccessResponse.ok(responseDto); } @@ -31,4 +31,12 @@ public ResponseEntity> searchKeyWordPost(@UserId final Long u final PostSearchResponseDto responseDto = postService.searchKeyWordPost(userId, key, type, pageable); return SuccessResponse.ok(responseDto); } + + @GetMapping("/search") + public ResponseEntity> searchTextPost(@UserId final Long userId, + @RequestParam final String text, + final Pageable pageable) { + final PostSearchResponseDto responseDto = postService.searchTextPost(userId, text, pageable); + return SuccessResponse.ok(responseDto); + } } From a02c9064acd331c1bdf83ce0207d969336831376 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Wed, 3 Jan 2024 21:27:00 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[feat]=20#17=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20api=20servic?= =?UTF-8?q?e=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/service/PostService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java index 48e3757..34c1054 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java +++ b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java @@ -11,7 +11,6 @@ import org.gachon.checkmate.domain.post.entity.SortType; import org.gachon.checkmate.domain.post.repository.PostQuerydslRepository; import org.gachon.checkmate.global.error.exception.EntityNotFoundException; -import org.gachon.checkmate.global.utils.EnumValueUtils; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -19,7 +18,6 @@ import java.time.LocalDate; import java.time.temporal.ChronoUnit; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -37,6 +35,17 @@ public class PostService { private final CheckListRepository checkListRepository; private final PostQuerydslRepository postQuerydslRepository; + public PostSearchResponseDto getAllPosts(Long userId, String type, Pageable pageable) { + CheckList checkList = getCheckList(userId); + SortType sortType = toEntityCode(SortType.class, type); + Page postSearchList = getAllPostsResults(pageable); + List searchResults = createPostSearchResponseDto(postSearchList, checkList); + sortByTypeForSearchResults(searchResults, Objects.requireNonNull(sortType)); + List pagingSearchResults + = convertPaging(searchResults, pageable.getOffset(), pageable.getPageSize()); + return PostSearchResponseDto.of(pagingSearchResults, postSearchList.getTotalPages(), postSearchList.getTotalElements()); + } + public PostSearchResponseDto searchKeyWordPost(Long userId, String key, String type, Pageable pageable) { CheckList checkList = getCheckList(userId); SortType sortType = toEntityCode(SortType.class, type); @@ -100,6 +109,10 @@ private int getRemainDate(LocalDate endDate) { return (int) endDate.until(LocalDate.now(), ChronoUnit.DAYS); } + private Page getAllPostsResults(Pageable pageable) { + return postQuerydslRepository.findAllPosts(pageable); + } + private Page getKeySearchResults(ImportantKeyType importantKeyType, Pageable pageable) { return postQuerydslRepository.searchKeyPost(importantKeyType, pageable); } From f0206e687fcfbd377652869d80cd5bb3402000d6 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Wed, 3 Jan 2024 21:27:13 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[feat]=20#17=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PostQuerydslRepository.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostQuerydslRepository.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostQuerydslRepository.java index c62ec9e..8158e65 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostQuerydslRepository.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostQuerydslRepository.java @@ -24,6 +24,29 @@ public class PostQuerydslRepository { private final JPAQueryFactory queryFactory; + public Page findAllPosts(Pageable pageable) { + List content = queryFactory + .select(new QPostSearchDto( + post.title, + post.content, + post.importantKeyType, + post.similarityKeyType, + post.endDate, + post.scrapList.size(), + postCheckList + )) + .from(post) + .leftJoin(post.postCheckList, postCheckList) + .where( + validatePostDate() + ) + .fetch(); + + JPAQuery countQuery = queryFactory + .selectFrom(post); + return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchCount); + } + public Page searchKeyPost(ImportantKeyType importantKeyType, Pageable pageable) { List content = queryFactory .select(new QPostSearchDto(