Skip to content

Commit

Permalink
Merge pull request #139 from Team-Shaka/fix/138
Browse files Browse the repository at this point in the history
🐛 Fix: 회원 가입은 했으나 소속 트리하우스가 없는 경우에 대한 처리
  • Loading branch information
koojun99 authored Oct 10, 2024
2 parents 6de4b0e + 7667ee5 commit 92dcb21
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/main/java/treehouse/server/api/user/business/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ public UserResponseDTO.checkUserStatus checkUserStatus(UserRequestDTO.checkUserS
Boolean isNewUser = !userQueryAdapter.existByPhoneNumber(request.getPhoneNumber());
Boolean isInvited = invitationQueryAdapter.existByPhoneNumber(request.getPhoneNumber());

// User가 존재하지만, 해당 User와 연결된 Member가 하나도 없는 경우
if (!isNewUser) {
User user = userQueryAdapter.findByPhoneNumber(request.getPhoneNumber());
// 해당 User와 연관된 Member가 없는지 확인
if (user.getMemberList().isEmpty()) {
List<Invitation> receivedInvitations = invitationQueryAdapter.findAllByPhone(request.getPhoneNumber());
receivedInvitations.forEach(invitation -> {
invitation.setReceiver(null);
invitationCommandAdapter.saveInvitation(invitation);
});
fcmService.deleteAllFcmToken(user);
userCommandAdapter.delete(user); // User 삭제

isNewUser = true; // 삭제했으므로 isNewUser를 true로 변경
}
}


return UserMapper.toCheckUserStatus(isNewUser, isInvited);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public TokenDTO reissueToken(User user, RefreshToken refreshToken){
}

public void withdraw(User user) {
user.withdraw();
}

public void delete(User user) {
userRepository.delete(user);
}
}
6 changes: 5 additions & 1 deletion src/main/java/treehouse/server/global/entity/User/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "user")
@SQLDelete(sql = "UPDATE user SET inactivated_at = NOW(), status = 'WITHDRAWAL' WHERE id = ?")
public class User extends BaseDateTimeEntity {

@Id
Expand Down Expand Up @@ -67,6 +66,11 @@ public class User extends BaseDateTimeEntity {
@OneToMany(mappedBy = "receiver")
List<Notification> notificationList;

public void withdraw() {
this.status = UserStatus.WITHDRAWAL;
this.inactivatedAt = LocalDateTime.now();
}

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

0 comments on commit 92dcb21

Please sign in to comment.