From 9bcb980179614841ed811d421e1fe5d02c44a736 Mon Sep 17 00:00:00 2001 From: yumzen Date: Sun, 4 Aug 2024 15:41:15 +0900 Subject: [PATCH] =?UTF-8?q?#46=20Feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=EB=B3=84=20=EB=82=B4=20=EB=8B=A4=EC=9D=B4=EC=96=B4?= =?UTF-8?q?=EB=A6=AC=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/repository/PostRepository.java | 6 ++---- .../global/service/MemberService/MemberQueryService.java | 5 +---- .../service/MemberService/MemberQueryServiceImpl.java | 9 ++++----- .../backend/global/web/controller/MemberController.java | 8 ++++++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/codiary/backend/global/repository/PostRepository.java b/src/main/java/com/codiary/backend/global/repository/PostRepository.java index 1ce2e6d4..3d96ead0 100644 --- a/src/main/java/com/codiary/backend/global/repository/PostRepository.java +++ b/src/main/java/com/codiary/backend/global/repository/PostRepository.java @@ -6,7 +6,6 @@ import com.codiary.backend.global.domain.entity.Team; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -50,7 +49,6 @@ public interface PostRepository extends JpaRepository { Page findByPostIdIn(List postIds, Pageable pageable); - @Query("SELECT p FROM Post p LEFT JOIN p.authorsList a WHERE p.member = :member OR a.member = :member ORDER BY p.createdAt DESC") - Page findPostsByMemberOrAuthor(@Param("member") Member member, Pageable pageable); - + @Query("SELECT p FROM Post p LEFT JOIN p.authorsList a LEFT JOIN p.categoriesList c WHERE (p.member = :member OR a.member = :member) AND LOWER(c.name) LIKE LOWER(:categoryName) ORDER BY p.createdAt DESC") + Page findPostsByMemberOrAuthorAndCategoryName(@Param("member") Member member, @Param("categoryName") String categoryName, Pageable pageable); } \ No newline at end of file diff --git a/src/main/java/com/codiary/backend/global/service/MemberService/MemberQueryService.java b/src/main/java/com/codiary/backend/global/service/MemberService/MemberQueryService.java index a6491ca8..dd5c2e4c 100644 --- a/src/main/java/com/codiary/backend/global/service/MemberService/MemberQueryService.java +++ b/src/main/java/com/codiary/backend/global/service/MemberService/MemberQueryService.java @@ -2,15 +2,12 @@ import com.codiary.backend.global.domain.entity.Member; import com.codiary.backend.global.domain.entity.Post; import com.codiary.backend.global.domain.entity.Bookmark; -import com.codiary.backend.global.domain.entity.mapping.MemberCategory; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import java.util.List; - public interface MemberQueryService { - Page getMyPosts(Member member, Pageable pageable); + Page getMyPosts(Member member, String category, Pageable pageable); // 회원별 북마크 리스트 조회 Page getBookmarkList(Long memberId, Integer page); diff --git a/src/main/java/com/codiary/backend/global/service/MemberService/MemberQueryServiceImpl.java b/src/main/java/com/codiary/backend/global/service/MemberService/MemberQueryServiceImpl.java index acc37189..2ed62105 100644 --- a/src/main/java/com/codiary/backend/global/service/MemberService/MemberQueryServiceImpl.java +++ b/src/main/java/com/codiary/backend/global/service/MemberService/MemberQueryServiceImpl.java @@ -5,14 +5,11 @@ import com.codiary.backend.global.domain.entity.Bookmark; import com.codiary.backend.global.domain.entity.Member; import com.codiary.backend.global.domain.entity.Post; -import com.codiary.backend.global.domain.entity.mapping.MemberCategory; import com.codiary.backend.global.repository.BookmarkRepository; -import com.codiary.backend.global.repository.MemberCategoryRepository; import com.codiary.backend.global.repository.MemberRepository; import com.codiary.backend.global.repository.PostRepository; import lombok.RequiredArgsConstructor; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -37,11 +34,13 @@ public class MemberQueryServiceImpl implements MemberQueryService { @Override - public Page getMyPosts(Member member, Pageable pageable) { - Page posts = postRepository.findPostsByMemberOrAuthor(member, pageable); + public Page getMyPosts(Member member, String category, Pageable pageable) { + Page posts = postRepository.findPostsByMemberOrAuthorAndCategoryName(member, category, pageable); posts.getContent().forEach(post -> { //proxy 초기화 post.getAuthorsList().size(); + post.getCategoriesList().size(); + post.getPostFileList().size(); }); return posts; diff --git a/src/main/java/com/codiary/backend/global/web/controller/MemberController.java b/src/main/java/com/codiary/backend/global/web/controller/MemberController.java index 8619b910..80f11e2e 100644 --- a/src/main/java/com/codiary/backend/global/web/controller/MemberController.java +++ b/src/main/java/com/codiary/backend/global/web/controller/MemberController.java @@ -103,10 +103,14 @@ public ApiResponse> getFollowers() { } + @Operation( + summary = "유저가 작성한 다이어리 목록 카테고리별 조회(페이지네이션)", + description = "category와 page를 입력해주세요." + ) @GetMapping("/posts") - public ApiResponse getMyDiaries(@PageableDefault(size=6) Pageable pageable){ + public ApiResponse getMyDiaries(@RequestParam(value = "category", required = false) String category, @PageableDefault(size=6) Pageable pageable){ Member member = memberCommandService.getRequester(); - Page posts = memberQueryService.getMyPosts(member, pageable); + Page posts = memberQueryService.getMyPosts(member, category, pageable); return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, PostConverter.toMemberPostPreviewListDTO(posts)); }