Skip to content

Commit

Permalink
Merge pull request #62 from Team-Shaka/refactor/61
Browse files Browse the repository at this point in the history
♻️ Refactor: Mapper 클래스 구조 변경과 NotificationType enum 추가
  • Loading branch information
CYY1007 authored Jun 21, 2024
2 parents bb7fe2b + 6e700e8 commit 9dffb63
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ public String reactToComment(User user, Long treehouseId, Long commentId, Commen
}

Reaction reaction = ReactionMapper.toCommentReaction(request, comment, member);
Reaction savedReaction = reactionCommandAdapter.saveReaction(reaction);

member.addReaction(savedReaction);

reactionCommandAdapter.saveReaction(reaction);
return request.getReactionName() + " is saved";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,36 @@

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import treehouse.server.api.member.presentation.dto.MemberRequestDTO;
import treehouse.server.api.member.presentation.dto.MemberResponseDTO;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.entity.member.Member;
import treehouse.server.global.entity.treeHouse.TreeHouse;

import java.util.ArrayList;

@Component
@RequiredArgsConstructor
public class MemberMapper {

public static Member toMember(User user, String memberName, String bio, String profileImageUrl, TreeHouse treeHouse) {
public static Member toMember(User user, MemberRequestDTO.registerMember request, TreeHouse treeHouse) {
return Member.builder()
.user(user)
.name(memberName)
.bio(bio)
.profileImageUrl(profileImageUrl)
.name(request.getMemberName())
.bio(request.getBio())
.profileImageUrl(request.getProfileImageURL())
.treeHouse(treeHouse)
.notificationList(new ArrayList<>())
.commentList(new ArrayList<>())
.invitationList(new ArrayList<>())
.reactionList(new ArrayList<>())
.build();
}

public static MemberResponseDTO.registerMember toRegister(Long treehouseId, Member member) {
public static MemberResponseDTO.registerMember toRegister(Member member) {
return MemberResponseDTO.registerMember.builder()
.userId(member.getUser().getId())
.treehouseId(treehouseId) // treehouseId는 관련 기능 구현 후 변경 예정
.treehouseId(member.getTreeHouse().getId())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ public class MemberService {
private final TreehouseQueryAdapter treehouseQueryAdapter;

/**
* 회원가입
* 트리하우스에 가입
* @param user
* @param request
* @return
*/
@Transactional
public MemberResponseDTO.registerMember register(User user, MemberRequestDTO.registerMember request){
TreeHouse treeHouse = treehouseQueryAdapter.getTreehouseById(request.getTreehouseId());
Member member = MemberMapper.toMember(user, request.getMemberName(),
request.getBio(), request.getProfileImageURL(), treeHouse);
Member member = MemberMapper.toMember(user, request, treeHouse);
Member savedMember = memberCommandAdapter.register(member);

return MemberMapper.toRegister(request.getTreehouseId(), savedMember); // treehouseId는 관련 기능 구현 후 변경
user.addMember(savedMember); // User에 Member 추가
treeHouse.addMember(savedMember); // TreeHouse에 Member 추가

return MemberMapper.toRegister(savedMember);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,18 @@ public String reactToPost(User user, Long treehouseId, Long postId, PostRequestD
Member member = memberQueryAdapter.findByUserAndTreehouse(user, treehouse);

Post post = postQueryAdapter.findById(postId);

Boolean isPushed = reactionQueryAdapter.existByMemberAndPostAndReactionName(member, post, request.getReactionName());
if (isPushed) {
reactionCommandAdapter.deletePostReaction(member, post, request.getReactionName());
return request.getReactionName() + " is deleted";
}

Reaction reaction = ReactionMapper.toPostReaction(request, post, member);
Reaction savedReaction = reactionCommandAdapter.saveReaction(reaction);

member.addReaction(savedReaction);

reactionCommandAdapter.saveReaction(reaction);
return request.getReactionName() + " is saved";
}
}
3 changes: 3 additions & 0 deletions src/main/java/treehouse/server/global/entity/User/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ public class User extends BaseDateTimeEntity {
@OneToMany(mappedBy = "user")
private List<Member> memberList;

public void addMember(Member member) {
memberList.add(member);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ public class Member extends BaseDateTimeEntity {
@OneToMany(mappedBy = "member")
List<Reaction> reactionList;


public void addReaction(Reaction reaction) {
reactionList.add(reaction);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package treehouse.server.global.entity.notification;

public enum NotificationType {
INVITATION, COMMENT, REACTION
INVITATION, COMMENT, REPLY, POST_REACTION, COMMENT_REACTION
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ public class TreeHouse extends BaseDateTimeEntity {

@OneToMany(mappedBy = "treeHouse")
private List<Invitation> invitationList;

public void addMember(Member member) {
memberList.add(member);
}
}

0 comments on commit 9dffb63

Please sign in to comment.