Skip to content

Commit

Permalink
feat: 게시글 조회 시 repost한 유저의 name도 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
hyxklee committed Nov 11, 2024
1 parent 518798c commit 85fce00
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PostResponseDto toPostResponseDto(Post post, User user, LikeRepository li
.build();
}

public ParentPostResponseDto toParentPostResponseDto(Post post, User user, LikeRepository likeRepository, Type postType, Long repostingUserId) {
public ParentPostResponseDto toParentPostResponseDto(Post post, User user, LikeRepository likeRepository, Type postType, Long repostingUserId, String reposingUserName) {
return ParentPostResponseDto.builder()
.id(post.getId())
.content(post.getContent())
Expand All @@ -50,6 +50,7 @@ public ParentPostResponseDto toParentPostResponseDto(Post post, User user, LikeR
.repostCount(post.getRepostCount())
.likeCount(post.getLikeCount())
.isLikedByUser(isLikedByUser(post, user, likeRepository))
.repostingUserName(reposingUserName)
.repostingUserId(repostingUserId)
.postType(postType)
.myPost(isMyPost(post, user))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public record ParentPostResponseDto(
Long replyCount,
Long repostCount,
Long likeCount,
String repostingUserName,
Long repostingUserId,
Type postType,
Boolean myPost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<ParentPostResponseDto> getAllParentPosts(String email) {
return posts.stream()
.filter(post -> !followedUserIds.contains(post.getUser().getId()))
.map(post -> {
return postMapper.toParentPostResponseDto(post, user, likeRepository, Type.POST, null);
return postMapper.toParentPostResponseDto(post, user, likeRepository, Type.POST, null, null);
})
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ private void check(Long userId, Long postId){
private List<ParentPostResponseDto> getUserPosts(User user, boolean isOwner) {
return user.getPosts().stream()
.filter(post -> post.getParent() == null)
.map(post -> postMapper.toParentPostResponseDto(post, user, likeRepository, Type.POST, null))
.map(post -> postMapper.toParentPostResponseDto(post, user, likeRepository, Type.POST, null, null))
.collect(Collectors.toList());
}

// 사용자의 리포스트를 가져오는 메서드
private List<ParentPostResponseDto> getUserReposts(User user, boolean isOwner) {
return user.getReposts().stream()
.map(repost -> postMapper.toParentPostResponseDto(repost.getPost(), user, likeRepository, Type.REPOST, repost.getUser().getId()))
.map(repost -> postMapper.toParentPostResponseDto(repost.getPost(), user, likeRepository, Type.REPOST, repost.getUser().getId(), repost.getUser().getName()))
.collect(Collectors.toList());
}

Expand All @@ -99,7 +99,7 @@ private List<ParentPostResponseDto> getFollowingUsersPosts(User user) {
.map(Follow::getFollowed)
.flatMap(followedUser -> followedUser.getPosts().stream())
.filter(post -> post.getParent() == null)
.map(post -> postMapper.toParentPostResponseDto(post, user, likeRepository, Type.POST, null))
.map(post -> postMapper.toParentPostResponseDto(post, user, likeRepository, Type.POST, null, null))
.collect(Collectors.toList());
}

Expand All @@ -108,7 +108,7 @@ private List<ParentPostResponseDto> getFollowingUsersReposts(User user) {
return user.getFollowingList().stream()
.map(Follow::getFollowed)
.flatMap(followedUser -> followedUser.getReposts().stream())
.map(repost -> postMapper.toParentPostResponseDto(repost.getPost(), user, likeRepository, Type.REPOST, repost.getUser().getId()))
.map(repost -> postMapper.toParentPostResponseDto(repost.getPost(), user, likeRepository, Type.REPOST, repost.getUser().getId(), repost.getUser().getName()))
.collect(Collectors.toList());
}

Expand Down

0 comments on commit 85fce00

Please sign in to comment.