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

Feature/75 - 트리하우스 정보 조회 API 및 하드코딩으로 채워뒀던 코드들 수정 #83

Merged
merged 3 commits into from
Jul 16, 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 @@ -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 @@ -23,6 +23,7 @@ public class InvitationMapper {
public static InvitationResponseDTO.getInvitation toGetInvitation (Invitation invitation, List<String> treeMemberProfileImages) {
return InvitationResponseDTO.getInvitation.builder()
.invitationId(invitation.getId())
.treehouseId(invitation.getTreeHouse().getId())
.treehouseName(invitation.getTreeHouse().getName())
.senderName(invitation.getSender().getName())
.senderProfileImageUrl(invitation.getSender().getProfileImageUrl())
Expand Down Expand Up @@ -63,6 +64,7 @@ public static Invitation toInvitation(String phoneNumber, Member sender, User re
.phone(phoneNumber)
.expiredAt(sevenDaysLater)
.status(InvitationStatus.PENDING)
.treeHouse(treeHouse)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import treehouse.server.global.entity.User.User;
import treehouse.server.global.entity.member.Member;
import treehouse.server.global.entity.treeHouse.TreeHouse;
import treehouse.server.global.exception.GlobalErrorCode;
import treehouse.server.global.exception.ThrowClass.InvitationException;
import treehouse.server.global.exception.ThrowClass.UserException;

import java.util.List;
Expand Down Expand Up @@ -64,7 +66,6 @@ public InvitationResponseDTO.myInvitationInfo getMyInvitationInfo(User user){

@Transactional
public InvitationResponseDTO.createInvitation createInvitation(User user, InvitationRequestDTO.createInvitation request){

// 트리 찾기
TreeHouse treehouse = treehouseQueryAdapter.getTreehouseById(request.getTreehouseId());
// 초대 멤버 찾기
Expand Down Expand Up @@ -92,8 +93,10 @@ public InvitationResponseDTO.createInvitation createInvitation(User user, Invita
public InvitationResponseDTO.invitationAccept decisionInvitation(User user, InvitationRequestDTO.invitationAcceptDecision request){
// 해당 User 에게 온 초대장인지 검증하는 로직 추가
Long treehouseId = 0L;
Invitation invitation = invitationQueryAdapter.findById(request.getInvitationId());

if (request.isAcceptDecision()==true) {
treehouseId = 1L; // treehouse 관련 로직 개발 후, invitation.getTreeHouse.getId() 등으로 바꾸기
treehouseId = invitation.getTreeHouse().getId(); // treehouse 관련 로직 개발 후, invitation.getTreeHouse.getId() 등으로 바꾸기
}
return InvitationMapper.toInvitationResult(treehouseId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import treehouse.server.global.entity.Invitation.Invitation;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.exception.GlobalErrorCode;
import treehouse.server.global.exception.ThrowClass.InvitationException;
import treehouse.server.global.exception.ThrowClass.UserException;

import java.util.List;
Expand All @@ -26,4 +27,9 @@ public List<Invitation> findAllByPhone(String phone) {
public Boolean existByPhoneNumber(String phoneNumber) {
return invitationRepository.existsByPhone(phoneNumber);
}

public Invitation findById(Long invitationId) {
return invitationRepository.findById(invitationId)
.orElseThrow(() -> new InvitationException(GlobalErrorCode.INVITATION_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class InvitationResponseDTO {
@AllArgsConstructor
public static class getInvitation {
private Long invitationId;
private Long treehouseId;
private String treehouseName;
private String senderName;
private String senderProfileImageUrl;
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ public static TreehouseResponseDTO.createTreehouse toCreateTreehouse(TreeHouse t
.treehouseId(treehouse.getId())
.build();
}

public static TreehouseResponseDTO.getTreehouseDetails toGetTreehouseDetails(TreeHouse treehouse) {
return TreehouseResponseDTO.getTreehouseDetails.builder()
.treehouseId(treehouse.getId())
.treehouseName(treehouse.getName())
.treehouseSize(treehouse.getMemberList().size())
.treehouseImageUrl(null) //TODO: 이미지 URL 설정
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.transaction.annotation.Transactional;
import treehouse.server.api.member.implementation.MemberQueryAdapter;
import treehouse.server.api.treehouse.implementation.TreehouseCommandAdapter;
import treehouse.server.api.treehouse.implementation.TreehouseQueryAdapter;
import treehouse.server.api.treehouse.presentation.dto.TreehouseRequestDTO;
import treehouse.server.api.treehouse.presentation.dto.TreehouseResponseDTO;
import treehouse.server.global.entity.treeHouse.TreeHouse;
Expand All @@ -17,6 +18,7 @@
public class TreehouseService {

private final TreehouseCommandAdapter treehouseCommandAdapter;
private final TreehouseQueryAdapter treehouseQueryAdapter;

private final MemberQueryAdapter memberQueryAdapter;

Expand All @@ -28,5 +30,10 @@ public TreehouseResponseDTO.createTreehouse createTreehouse(TreehouseRequestDTO.
return TreehouseMapper.toCreateTreehouse(savedTreehouse);
}

public TreehouseResponseDTO.getTreehouseDetails getTreehouseDetails(Long treehouseId) {
TreeHouse treehouse = treehouseQueryAdapter.getTreehouseById(treehouseId);
return TreehouseMapper.toGetTreehouseDetails(treehouse);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import treehouse.server.api.treehouse.business.TreehouseService;
import treehouse.server.api.treehouse.presentation.dto.TreehouseRequestDTO;
import treehouse.server.api.treehouse.presentation.dto.TreehouseResponseDTO;
Expand All @@ -31,4 +28,12 @@ public CommonResponse<TreehouseResponseDTO.createTreehouse> createTreehouse(
) {
return CommonResponse.onSuccess(treehouseService.createTreehouse(request));
}

@GetMapping("/{treehouseId}")
@Operation(summary = "트리하우스 조회 🔑", description = "트리하우스 정보를 조회합니다.")
public CommonResponse<TreehouseResponseDTO.getTreehouseDetails> getTreehouseDetails(
@PathVariable Long treehouseId
) {
return CommonResponse.onSuccess(treehouseService.getTreehouseDetails(treehouseId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ public static class createTreehouse {

private Long treehouseId;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class getTreehouseDetails {

private Long treehouseId;
private String treehouseName;
private Integer treehouseSize;
private String treehouseImageUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Invitation extends BaseDateTimeEntity {
private String phone;

@Setter
@Enumerated(EnumType.STRING)
private InvitationStatus status;

private LocalDateTime expiredAt; //초대장 만료일자
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package treehouse.server.global.exception.ThrowClass;

import treehouse.server.global.exception.BaseErrorCode;

public class InvitationException extends GeneralException{

public InvitationException(BaseErrorCode errorCode) {
super(errorCode);
}
}
Loading