Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 카테고리별 내 다이어리 목록 조회 #76

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,7 +49,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {

Page<Post> findByPostIdIn(List<Long> 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<Post> 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<Post> findPostsByMemberOrAuthorAndCategoryName(@Param("member") Member member, @Param("categoryName") String categoryName, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Post> getMyPosts(Member member, Pageable pageable);
Page<Post> getMyPosts(Member member, String category, Pageable pageable);

// 회원별 북마크 리스트 조회
Page<Bookmark> getBookmarkList(Long memberId, Integer page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,11 +34,13 @@ public class MemberQueryServiceImpl implements MemberQueryService {


@Override
public Page<Post> getMyPosts(Member member, Pageable pageable) {
Page<Post> posts = postRepository.findPostsByMemberOrAuthor(member, pageable);
public Page<Post> getMyPosts(Member member, String category, Pageable pageable) {
Page<Post> posts = postRepository.findPostsByMemberOrAuthorAndCategoryName(member, category, pageable);

posts.getContent().forEach(post -> { //proxy 초기화
post.getAuthorsList().size();
post.getCategoriesList().size();
post.getPostFileList().size();
});

return posts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,14 @@ public ApiResponse<List<MemberSumResponseDto>> getFollowers() {
}


@Operation(
summary = "유저가 작성한 다이어리 목록 카테고리별 조회(페이지네이션)",
description = "category와 page를 입력해주세요."
)
@GetMapping("/posts")
public ApiResponse<PostResponseDTO.MemberPostPreviewListDTO> getMyDiaries(@PageableDefault(size=6) Pageable pageable){
public ApiResponse<PostResponseDTO.MemberPostPreviewListDTO> getMyDiaries(@RequestParam(value = "category", required = false) String category, @PageableDefault(size=6) Pageable pageable){
Member member = memberCommandService.getRequester();
Page<Post> posts = memberQueryService.getMyPosts(member, pageable);
Page<Post> posts = memberQueryService.getMyPosts(member, category, pageable);
return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, PostConverter.toMemberPostPreviewListDTO(posts));
}

Expand Down
Loading