Skip to content

Commit

Permalink
⚡️ Improve: 초대장 로직 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
koojun99 committed Sep 15, 2024
1 parent 3d64046 commit dcb4cbb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public InvitationResponseDTO.invitationAccept decisionInvitation(User user, Invi
if (request.isAcceptDecision()==true) {
treehouseId = invitation.getTreeHouse().getId(); // treehouse 관련 로직 개발 후, invitation.getTreeHouse.getId() 등으로 바꾸기
// 초대장 수락

invitationCommandAdapter.acceptInvitation(invitation);
}
return InvitationMapper.toInvitationResult(treehouseId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import treehouse.server.api.invitation.persistence.InvitationRepository;
import treehouse.server.global.annotations.Adapter;
import treehouse.server.global.entity.Invitation.Invitation;
import treehouse.server.global.entity.Invitation.InvitationStatus;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.entity.User.UserRole;
import treehouse.server.global.entity.redis.RefreshToken;
Expand All @@ -27,4 +28,12 @@ public Invitation saveInvitation(Invitation invitation){
return invitationRepository.save(invitation);
}

public void deleteInvitation(Invitation invitation){
invitationRepository.delete(invitation);
}

public void acceptInvitation(Invitation invitation) {
invitation.setStatus(InvitationStatus.ACCEPTED);
invitationRepository.save(invitation);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package treehouse.server.api.invitation.implement;

import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import treehouse.server.api.invitation.persistence.InvitationRepository;
import treehouse.server.api.invitation.presentation.dto.InvitationRequestDTO;
import treehouse.server.global.annotations.Adapter;
import treehouse.server.global.entity.Invitation.Invitation;
import treehouse.server.global.entity.Invitation.InvitationStatus;
import treehouse.server.global.entity.User.User;
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;
import java.util.Optional;

@Adapter
@RequiredArgsConstructor
Expand All @@ -23,7 +19,8 @@ public class InvitationQueryAdapter {
private final InvitationRepository invitationRepository;

public List<Invitation> findAllByPhone(String phone) {
return invitationRepository.findAllByPhone(phone);
return invitationRepository.findAllByPhone(phone)
.stream().filter(invitation -> invitation.getStatus().equals(InvitationStatus.PENDING)).toList();
}

public Boolean existByPhoneNumber(String phoneNumber) {
Expand All @@ -39,12 +36,13 @@ public Boolean existByPhoneAndTreehouse(String phoneNumber, TreeHouse treehouse)
return invitationRepository.existsByPhoneAndTreeHouse(phoneNumber, treehouse);
}

public Invitation findByReceiverAndTreeHouse(User user, TreeHouse treeHouse) {
return invitationRepository.findByReceiverAndTreeHouse(user, treeHouse)
.orElseThrow(() -> new InvitationException(GlobalErrorCode.INVITATION_NOT_FOUND));
}

public Invitation findByPhoneAndTreeHouse(String phone, TreeHouse treeHouse) {
return invitationRepository.findByPhoneAndTreeHouse(phone, treeHouse);
}

public Invitation findAcceptedInvitation(User user, TreeHouse treeHouse) {
return invitationRepository.findByReceiverAndTreeHouse(user, treeHouse)
.filter(invitation -> invitation.getStatus().equals(InvitationStatus.ACCEPTED))
.orElseThrow(() -> new InvitationException(GlobalErrorCode.INVITATION_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import org.springframework.transaction.annotation.Transactional;
import treehouse.server.api.branch.business.BranchService;
import treehouse.server.api.branch.implementation.BranchQueryAdapter;
import treehouse.server.api.invitation.implement.InvitationCommandAdapter;
import treehouse.server.api.invitation.implement.InvitationQueryAdapter;
import treehouse.server.api.member.implementation.MemberCommandAdapter;
import treehouse.server.api.member.implementation.MemberQueryAdapter;
import treehouse.server.api.member.presentation.dto.MemberRequestDTO;
import treehouse.server.api.member.presentation.dto.MemberResponseDTO;
import treehouse.server.api.treehouse.implementation.TreehouseQueryAdapter;
import treehouse.server.global.entity.Invitation.Invitation;
import treehouse.server.global.entity.Invitation.InvitationStatus;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.entity.branch.Branch;
import treehouse.server.global.entity.member.Member;
Expand All @@ -30,6 +32,8 @@ public class MemberService {
private final MemberCommandAdapter memberCommandAdapter;
private final TreehouseQueryAdapter treehouseQueryAdapter;
private final BranchQueryAdapter branchQueryAdapter;

private final InvitationCommandAdapter invitationCommandAdapter;
private final InvitationQueryAdapter invitationQueryAdapter;

private final BranchService branchService;
Expand All @@ -50,8 +54,8 @@ public MemberResponseDTO.registerMember register(User user, MemberRequestDTO.reg
treeHouse.addMember(savedMember); // TreeHouse에 Member 추가

// 트리하우스에 초대한 멤버와의 브랜치 생성
Invitation invitation = invitationQueryAdapter.findByReceiverAndTreeHouse(user, treeHouse);
branchService.createBranch(treeHouse, invitation.getSender(), savedMember);
Invitation acceptedInvitation = invitationQueryAdapter.findAcceptedInvitation(user, treeHouse);
branchService.createBranch(treeHouse, acceptedInvitation.getSender(), savedMember);

return MemberMapper.toRegister(savedMember);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ jwt:
key: ${JWT_SECRET}
# secret : ${JWT_SECRET}
authorities-key: authoritiesKey
access-token-validity-in-seconds: 180000 # 3 min
refresh-token-validity-in-seconds: 600000 # 5 min
access-token-validity-in-seconds: 600000 # 10 min
refresh-token-validity-in-seconds: 1200000 # 20 min

firebase:
admin-sdk: ${FCM_KEY}
Expand Down

0 comments on commit dcb4cbb

Please sign in to comment.