From 8132b7f4ce3069fe7926268ae36b179a3941e36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B5=AC=ED=99=98=EC=A4=80/=EB=AA=A8=EA=B1=B4?= Date: Thu, 7 Mar 2024 14:10:43 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]/#68-=ED=94=BC=EB=93=9C=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=8B=9C,=20treeId,=20treeName=20=ED=95=A8=EA=BB=98=20?= =?UTF-8?q?=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostController.java | 2 +- .../domain/post/converter/PostConverter.java | 19 +++++-------------- .../tree/domain/post/dto/PostResponseDTO.java | 14 +++----------- .../tree/domain/post/service/PostService.java | 7 ++++--- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/example/tree/domain/post/controller/PostController.java b/src/main/java/org/example/tree/domain/post/controller/PostController.java index 0dd15ce..8e46a31 100644 --- a/src/main/java/org/example/tree/domain/post/controller/PostController.java +++ b/src/main/java/org/example/tree/domain/post/controller/PostController.java @@ -31,7 +31,7 @@ public ApiResponse createPost( @GetMapping("/trees/{treeId}/feed") @Operation(summary = "피드 조회", description = "특정 트리하우스 속 피드를 불러옵니다.") - public ApiResponse> getFeed( + public ApiResponse getFeed( @PathVariable final Long treeId, @RequestHeader("Authorization") final String header ) { diff --git a/src/main/java/org/example/tree/domain/post/converter/PostConverter.java b/src/main/java/org/example/tree/domain/post/converter/PostConverter.java index 4c660ff..cb5dd0b 100644 --- a/src/main/java/org/example/tree/domain/post/converter/PostConverter.java +++ b/src/main/java/org/example/tree/domain/post/converter/PostConverter.java @@ -7,6 +7,7 @@ import org.example.tree.domain.post.entity.PostImage; import org.example.tree.domain.profile.entity.Profile; import org.example.tree.domain.reaction.dto.ReactionResponseDTO; +import org.example.tree.domain.tree.entity.Tree; import org.example.tree.global.common.amazons3.S3UploadService; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; @@ -44,21 +45,11 @@ public PostResponseDTO.createPost toCreatePost(Post savedPost) { .build(); } - public PostResponseDTO.getFeed toGetFeed(Post post, int branchDegree, List reactions) { - List imageUrls = post.getPostImages().stream() - .map(PostImage::getImageUrl) - .collect(Collectors.toList()); + public PostResponseDTO.getFeed toGetFeed(Tree tree, List posts) { return PostResponseDTO.getFeed.builder() - .postId(post.getId()) - .authorId(post.getProfile().getId()) - .profileImageUrl(post.getProfile().getProfileImageUrl()) - .memberName(post.getProfile().getMemberName()) - .branchDegree(branchDegree) - .content(post.getContent()) - .postImageUrls(imageUrls) - .createdAt(post.getCreatedAt()) - .reactions(reactions) - .commentCount(post.getCommentCount()) + .treeId(tree.getId()) + .treeName(tree.getName()) + .posts(posts) .build(); } diff --git a/src/main/java/org/example/tree/domain/post/dto/PostResponseDTO.java b/src/main/java/org/example/tree/domain/post/dto/PostResponseDTO.java index 965861a..5b2e3e2 100644 --- a/src/main/java/org/example/tree/domain/post/dto/PostResponseDTO.java +++ b/src/main/java/org/example/tree/domain/post/dto/PostResponseDTO.java @@ -26,17 +26,9 @@ public static class createPost { @NoArgsConstructor @AllArgsConstructor public static class getFeed { - - private Long postId; - private Long authorId; - private String profileImageUrl; - private String memberName; - private int branchDegree; - private String content; - private List postImageUrls; - private LocalDateTime createdAt; - private Integer commentCount; - private List reactions; + private Long treeId; + private String treeName; + private List posts; } diff --git a/src/main/java/org/example/tree/domain/post/service/PostService.java b/src/main/java/org/example/tree/domain/post/service/PostService.java index 36534a7..8173314 100644 --- a/src/main/java/org/example/tree/domain/post/service/PostService.java +++ b/src/main/java/org/example/tree/domain/post/service/PostService.java @@ -50,19 +50,20 @@ public PostResponseDTO.createPost createPost(Long treeId, PostRequestDTO.createP } @Transactional - public List getFeed(Long treeId, String token) { + public PostResponseDTO.getFeed getFeed(Long treeId, String token) { Profile profile = profileService.getTreeProfile(token, treeId); List posts = postQueryService.getPosts(profile.getTree()); - return posts.stream() + List treePosts = posts.stream() .map(post -> { // 작성자와의 branch degree를 가져옵니다. int branchDegree = branchService.calculateBranchDegree(treeId, profile.getId(), post.getProfile().getId()); // 각 포스트에 대한 반응들을 가져옵니다. List reactions = reactionService.getPostReactions(treeId, post.getId(), token); // Post와 해당 Post의 반응들을 포함하여 DTO를 생성합니다. - return postConverter.toGetFeed(post, branchDegree, reactions); + return postConverter.toGetPost(post, branchDegree, reactions); }) .collect(Collectors.toList()); + return postConverter.toGetFeed(profile.getTree(),treePosts); } @Transactional