diff --git a/src/main/java/treehouse/server/api/invitation/business/InvitationService.java b/src/main/java/treehouse/server/api/invitation/business/InvitationService.java index 1ebae1b..c003110 100644 --- a/src/main/java/treehouse/server/api/invitation/business/InvitationService.java +++ b/src/main/java/treehouse/server/api/invitation/business/InvitationService.java @@ -4,7 +4,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import treehouse.server.api.branch.business.BranchService; import treehouse.server.api.invitation.implement.InvitationCommandAdapter; import treehouse.server.api.invitation.implement.InvitationQueryAdapter; import treehouse.server.api.invitation.presentation.dto.InvitationRequestDTO; @@ -21,7 +20,6 @@ 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.stream.Collectors; @@ -50,7 +48,7 @@ public class InvitationService { @Transactional public InvitationResponseDTO.getInvitations getInvitations(User user) { - List invitations = invitationQueryAdapter.findAllByPhone(user.getPhone()); + List invitations = invitationQueryAdapter.findAllPendingByPhone(user.getPhone()); List invitationDtos = invitations.stream() .map(invitation -> { diff --git a/src/main/java/treehouse/server/api/invitation/implement/InvitationQueryAdapter.java b/src/main/java/treehouse/server/api/invitation/implement/InvitationQueryAdapter.java index 9139083..bcc9846 100644 --- a/src/main/java/treehouse/server/api/invitation/implement/InvitationQueryAdapter.java +++ b/src/main/java/treehouse/server/api/invitation/implement/InvitationQueryAdapter.java @@ -18,7 +18,7 @@ public class InvitationQueryAdapter { private final InvitationRepository invitationRepository; - public List findAllByPhone(String phone) { + public List findAllPendingByPhone(String phone) { return invitationRepository.findAllByPhone(phone) .stream().filter(invitation -> invitation.getStatus().equals(InvitationStatus.PENDING)).toList(); } @@ -45,4 +45,8 @@ public Invitation findAcceptedInvitation(User user, TreeHouse treeHouse) { .filter(invitation -> invitation.getStatus().equals(InvitationStatus.ACCEPTED)) .orElseThrow(() -> new InvitationException(GlobalErrorCode.INVITATION_NOT_FOUND)); } + + public List findAllByPhone(String phone) { + return invitationRepository.findAllByPhone(phone); + } } diff --git a/src/main/java/treehouse/server/api/user/business/UserService.java b/src/main/java/treehouse/server/api/user/business/UserService.java index 600e622..f8d4f3f 100644 --- a/src/main/java/treehouse/server/api/user/business/UserService.java +++ b/src/main/java/treehouse/server/api/user/business/UserService.java @@ -17,7 +17,6 @@ import treehouse.server.global.entity.redis.RefreshToken; import treehouse.server.global.exception.GlobalErrorCode; import treehouse.server.global.exception.ThrowClass.AuthException; -import treehouse.server.global.exception.ThrowClass.GeneralException; import treehouse.server.global.fcm.service.FcmService; import treehouse.server.global.redis.service.RedisService; import treehouse.server.global.security.jwt.dto.TokenDTO; @@ -59,7 +58,7 @@ public User findById(Long id){ public UserResponseDTO.registerUser register(UserRequestDTO.registerUser request){ User user = UserMapper.toUser(request.getUserName(), request.getPhoneNumber()); User savedUser = userCommandAdapter.register(user); - List receivedInvitations = invitationQueryAdapter.findAllByPhone(request.getPhoneNumber()); + List receivedInvitations = invitationQueryAdapter.findAllPendingByPhone(request.getPhoneNumber()); receivedInvitations.forEach(invitation -> { invitation.setReceiver(savedUser); invitationCommandAdapter.saveInvitation(invitation); @@ -93,7 +92,7 @@ public UserResponseDTO.reissue reissue(UserRequestDTO.reissue request){ return UserMapper.toReissue(token.getAccessToken(), token.getRefreshToken()); } - + @Transactional public UserResponseDTO.checkUserStatus checkUserStatus(UserRequestDTO.checkUserStatus request) { Boolean isNewUser = !userQueryAdapter.existByPhoneNumber(request.getPhoneNumber()); diff --git a/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java b/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java index 78091a6..b96643e 100644 --- a/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java +++ b/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java @@ -28,7 +28,7 @@ public class Invitation extends BaseDateTimeEntity { private LocalDateTime expiredAt; //초대장 만료일자 - @JoinColumn(name = "senderId") + @JoinColumn(name = "senderId", nullable = true) @ManyToOne(fetch = FetchType.LAZY) private Member sender;