Skip to content

Commit

Permalink
✨ Feat: 게시글/댓글 작성자 프로필 데이터에서 Branch 지수 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
koojun99 committed Jul 10, 2024
1 parent a890498 commit 13a5d29
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import treehouse.server.api.member.business.MemberMapper;
import treehouse.server.api.reaction.presentation.dto.ReactionResponseDTO;
import treehouse.server.global.common.util.TimeFormatter;
import treehouse.server.global.entity.branch.Branch;
import treehouse.server.global.entity.comment.Comment;
import treehouse.server.global.entity.comment.CommentType;
import treehouse.server.global.entity.member.Member;
Expand All @@ -14,26 +15,26 @@
public class CommentMapper {


public static CommentResponseDTO.CommentInfoDto toCommentInfoDto(Comment comment, ReactionResponseDTO.getReactionList reactionList,
public static CommentResponseDTO.CommentInfoDto toCommentInfoDto(Member member, List<Branch> branches, Comment comment, ReactionResponseDTO.getReactionList reactionList,
List<CommentResponseDTO.ReplyInfoDto> replyInfoDtoList) {
return CommentResponseDTO.CommentInfoDto.builder()
.commentedAt(TimeFormatter.format(comment.getCreatedAt()))
.commentId(comment.getId())
.context(comment.getContent())
.reactionList(reactionList)
.replyList(replyInfoDtoList)
.memberProfile(MemberMapper.toGetWriterProfile(comment.getWriter()))
.memberProfile(MemberMapper.toGetWriterProfile(member, comment.getWriter(), branches))
.build();

}

public static CommentResponseDTO.ReplyInfoDto toReplyInfoDto(Comment comment, ReactionResponseDTO.getReactionList reactionList) {
public static CommentResponseDTO.ReplyInfoDto toReplyInfoDto(Member member, List<Branch> branches, Comment comment, ReactionResponseDTO.getReactionList reactionList) {
return CommentResponseDTO.ReplyInfoDto.builder()
.commentedAt(TimeFormatter.format(comment.getCreatedAt()))
.commentId(comment.getId())
.context(comment.getContent())
.reactionList(reactionList)
.memberProfile(MemberMapper.toGetWriterProfile(comment.getWriter()))
.memberProfile(MemberMapper.toGetWriterProfile(member, comment.getWriter(), branches))
.build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import treehouse.server.api.branch.implementation.BranchQueryAdapter;
import treehouse.server.api.comment.implementation.CommentCommandAdapter;
import treehouse.server.api.comment.implementation.CommentQueryAdapter;
import treehouse.server.api.comment.presentation.dto.CommentRequestDTO;
Expand All @@ -23,6 +24,7 @@
import treehouse.server.api.treehouse.implementation.TreehouseQueryAdapter;
import treehouse.server.api.user.implement.UserQueryAdapter;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.entity.branch.Branch;
import treehouse.server.global.entity.comment.Comment;
import treehouse.server.global.entity.comment.CommentType;
import treehouse.server.global.entity.member.Member;
Expand Down Expand Up @@ -59,6 +61,8 @@ public class CommentService {
private final ReactionCommandAdapter reactionCommandAdapter;
private final ReactionQueryAdapter reactionQueryAdapter;

private final BranchQueryAdapter branchQueryAdapter;


public void reportComment(User user, CommentRequestDTO.reportComment request, Long treehouseId, Long postId, Long commentId){

Expand Down Expand Up @@ -86,6 +90,7 @@ public CommentResponseDTO.CommentListDto getCommentResponseList(User user, Long

TreeHouse treehouse = treehouseQueryAdapter.getTreehouseById(treehouseId);
Member member = memberQueryAdapter.findByUserAndTreehouse(user, treehouse);
List<Branch> branches = branchQueryAdapter.findAllByTreeHouse(treehouse);

Pageable pageable = PageRequest.of(page, 10, Sort.by(Sort.Direction.DESC, "createdAt"));
// List<Comment> commentListByPostId = commentQueryAdapter.getCommentListByPostId(postId, pageable);
Expand Down Expand Up @@ -134,11 +139,11 @@ public CommentResponseDTO.CommentListDto getCommentResponseList(User user, Long
));
ReactionResponseDTO.getReactionList replyReactionDtoList = ReactionMapper.toGetReactionList(replyReactionMap);

return CommentMapper.toReplyInfoDto(reply, replyReactionDtoList);
return CommentMapper.toReplyInfoDto(member, branches, reply, replyReactionDtoList);
})
.collect(Collectors.toList());

return CommentMapper.toCommentInfoDto(comment, reactionDtoList,replyInfoDtoList);
return CommentMapper.toCommentInfoDto(member, branches, comment, reactionDtoList,replyInfoDtoList);
})
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public static MemberResponseDTO.registerMember toRegister(Member member) {
.build();
}

public static MemberResponseDTO.getWriterProfile toGetWriterProfile(Member member) {
public static MemberResponseDTO.getWriterProfile toGetWriterProfile(Member member, Member writer, List<Branch> branches) {
return MemberResponseDTO.getWriterProfile.builder()
.memberId(member.getId())
.memberName(member.getName())
.memberProfileImageUrl(member.getProfileImageUrl())
.memberBranch(3) // Branch 기능 개발 이후 변경 예정
.memberId(writer.getId())
.memberName(writer.getName())
.memberProfileImageUrl(writer.getProfileImageUrl())
.memberBranch(BranchUtil.calculateBranchDegree(branches, member.getId(), writer.getId()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import treehouse.server.api.member.business.MemberMapper;
import treehouse.server.api.reaction.presentation.dto.ReactionResponseDTO;
import treehouse.server.global.common.util.TimeFormatter;
import treehouse.server.global.entity.branch.Branch;
import treehouse.server.global.entity.member.Member;
import treehouse.server.global.entity.post.Post;
import treehouse.server.global.entity.post.PostImage;
Expand All @@ -19,9 +20,9 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PostMapper {

public static PostResponseDTO.getPostDetails toGetPostDetails(Post post, List<String> postImageUrlList, ReactionResponseDTO.getReactionList reactionList) {
public static PostResponseDTO.getPostDetails toGetPostDetails(Member member, List<Branch> branches, Post post, List<String> postImageUrlList, ReactionResponseDTO.getReactionList reactionList) {
return PostResponseDTO.getPostDetails.builder()
.memberProfile(MemberMapper.toGetWriterProfile(post.getWriter()))
.memberProfile(MemberMapper.toGetWriterProfile(member, post.getWriter(), branches))
.postId(post.getId())
.context(post.getContent())
.pictureUrlList(postImageUrlList)
Expand All @@ -42,9 +43,9 @@ public static PostResponseDTO.getOnlyPostDetail toGetOnlyPostDetails(Post post,
.build();
}

public static PostResponseDTO.getMemberPostList toGetMemberPostList(Member targetMember, List<PostResponseDTO.getOnlyPostDetail> onlyPostDetailList) {
public static PostResponseDTO.getMemberPostList toGetMemberPostList(Member member, Member targetMember, List<PostResponseDTO.getOnlyPostDetail> onlyPostDetailList, List<Branch> branches) {
return PostResponseDTO.getMemberPostList.builder()
.memberProfile(MemberMapper.toGetWriterProfile(targetMember))
.memberProfile(MemberMapper.toGetWriterProfile(member, targetMember, branches))
.postList(onlyPostDetailList)
.build();
}
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/treehouse/server/api/post/business/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import treehouse.server.api.branch.implementation.BranchQueryAdapter;
import treehouse.server.api.member.implementation.MemberQueryAdapter;
import treehouse.server.api.post.implement.PostCommandAdapter;
import treehouse.server.api.post.implement.PostImageCommandAdapter;
Expand All @@ -25,6 +26,7 @@
import treehouse.server.api.treehouse.implementation.TreehouseQueryAdapter;
import treehouse.server.global.constants.Consts;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.entity.branch.Branch;
import treehouse.server.global.entity.member.Member;
import treehouse.server.global.entity.post.Post;
import treehouse.server.global.entity.post.PostImage;
Expand Down Expand Up @@ -65,6 +67,9 @@ public class PostService {
private final ReactionQueryAdapter reactionQueryAdapter;

private final ReportQueryAdapter reportQueryAdapter;

private final BranchQueryAdapter branchQueryAdapter;

/**
* 게시글 상세조회
*
Expand Down Expand Up @@ -100,7 +105,8 @@ public PostResponseDTO.getPostDetails getPostDetails(User user, Long postId, Lon

ReactionResponseDTO.getReactionList reactionDtoList = ReactionMapper.toGetReactionList(reactionMap);

return PostMapper.toGetPostDetails(post, postImageUrlList, reactionDtoList);
List<Branch> branches = branchQueryAdapter.findAllByTreeHouse(treehouse); // 트리하우스 내 모든 브랜치 조회
return PostMapper.toGetPostDetails(member, branches, post, postImageUrlList, reactionDtoList);
}

public PostResponseDTO.createPostResult createPost(User user, PostRequestDTO.createPost request, Long treehouseId) {
Expand Down Expand Up @@ -142,6 +148,7 @@ public List<PostResponseDTO.getPostDetails> getPosts (User user, Long treehouseI

TreeHouse treehouse = treehouseQueryAdapter.getTreehouseById(treehouseId);
Member member = memberQueryAdapter.findByUserAndTreehouse(user, treehouse);
List<Branch> branches = branchQueryAdapter.findAllByTreeHouse(treehouse);

Pageable pageable = PageRequest.of(page, 10, Sort.by(Sort.Direction.DESC, "createdAt"));
List<Post> postList = postQueryAdapter.findAllByTreehouse(treehouse, pageable);
Expand Down Expand Up @@ -170,7 +177,7 @@ public List<PostResponseDTO.getPostDetails> getPosts (User user, Long treehouseI
));

ReactionResponseDTO.getReactionList reactionDtoList = ReactionMapper.toGetReactionList(reactionMap);
return PostMapper.toGetPostDetails(post, postImageUrlList, reactionDtoList);
return PostMapper.toGetPostDetails(member, branches, post, postImageUrlList, reactionDtoList);
})
.collect(Collectors.toList());

Expand All @@ -183,6 +190,7 @@ public PostResponseDTO.getMemberPostList getMemberPosts(User user, Long targetMe
TreeHouse treehouse = treehouseQueryAdapter.getTreehouseById(treehouseId);
Member member = memberQueryAdapter.findByUserAndTreehouse(user, treehouse);
Member targetMember = memberQueryAdapter.findById(targetMemberId);
List<Branch> branches = branchQueryAdapter.findAllByTreeHouse(treehouse);

List<Post> postListByMember = postQueryAdapter.findAllByTreeHouseAndWriter(treehouse, targetMember, pageable);

Expand Down Expand Up @@ -211,7 +219,7 @@ public PostResponseDTO.getMemberPostList getMemberPosts(User user, Long targetMe
})
.collect(Collectors.toList());

return PostMapper.toGetMemberPostList(targetMember, postDtoList);
return PostMapper.toGetMemberPostList(member, targetMember, postDtoList, branches);
}


Expand Down

0 comments on commit 13a5d29

Please sign in to comment.