Skip to content

Commit

Permalink
[FEAT]/#68-피드조회 시, treeId, treeName 함께 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
koojun99 committed Mar 7, 2024
1 parent 32033f4 commit 8132b7f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ApiResponse<PostResponseDTO.createPost> createPost(

@GetMapping("/trees/{treeId}/feed")
@Operation(summary = "피드 조회", description = "특정 트리하우스 속 피드를 불러옵니다.")
public ApiResponse<List<PostResponseDTO.getFeed>> getFeed(
public ApiResponse<PostResponseDTO.getFeed> getFeed(
@PathVariable final Long treeId,
@RequestHeader("Authorization") final String header
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,21 +45,11 @@ public PostResponseDTO.createPost toCreatePost(Post savedPost) {
.build();
}

public PostResponseDTO.getFeed toGetFeed(Post post, int branchDegree, List<ReactionResponseDTO.getReaction> reactions) {
List<String> imageUrls = post.getPostImages().stream()
.map(PostImage::getImageUrl)
.collect(Collectors.toList());
public PostResponseDTO.getFeed toGetFeed(Tree tree, List<PostResponseDTO.getPost> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> postImageUrls;
private LocalDateTime createdAt;
private Integer commentCount;
private List<ReactionResponseDTO.getReaction> reactions;
private Long treeId;
private String treeName;
private List<PostResponseDTO.getPost> posts;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ public PostResponseDTO.createPost createPost(Long treeId, PostRequestDTO.createP
}

@Transactional
public List<PostResponseDTO.getFeed> getFeed(Long treeId, String token) {
public PostResponseDTO.getFeed getFeed(Long treeId, String token) {
Profile profile = profileService.getTreeProfile(token, treeId);
List<Post> posts = postQueryService.getPosts(profile.getTree());
return posts.stream()
List<PostResponseDTO.getPost> treePosts = posts.stream()
.map(post -> {
// 작성자와의 branch degree를 가져옵니다.
int branchDegree = branchService.calculateBranchDegree(treeId, profile.getId(), post.getProfile().getId());
// 각 포스트에 대한 반응들을 가져옵니다.
List<ReactionResponseDTO.getReaction> 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
Expand Down

0 comments on commit 8132b7f

Please sign in to comment.