diff --git a/src/main/java/com/taba/nimonaemo/member/model/entity/Member.java b/src/main/java/com/taba/nimonaemo/member/model/entity/Member.java index 24f8748..ac300f2 100644 --- a/src/main/java/com/taba/nimonaemo/member/model/entity/Member.java +++ b/src/main/java/com/taba/nimonaemo/member/model/entity/Member.java @@ -21,6 +21,8 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Member extends BaseEntity { + public static String DELETED_MEMBER = "탈퇴한 회원"; + @Id @GeneratedValue @Column(name = "member_id") @@ -65,4 +67,56 @@ private Member(@NotNull String name, this.memberRole = memberRole; this.status = status; } + + + public String getName() { + if (!getStatus().isActive()) { + return DELETED_MEMBER; + } + return this.name; + } + + public String getNickName() { + if (!getStatus().isActive()) { + return DELETED_MEMBER; + } + return this.nickname; + } + + /** + * Member 상태를 변경합니다. + * + * @param status 상태 + */ + public void changeStatus(MemberStatus status) { + this.status = status; + } + + /** + * 이름을 변경합니다. + * + * @param name 이름 + */ + public void changeName(String name) { + this.name = name; + } + + /** + * 닉네임(아이디)를 변경합니다. + * + * @param nickname 닉네임(아이디) + */ + public void changeNickname(String nickname) { + this.nickname = nickname; + } + + /** + * 탈퇴한 Member의 정보를 수정합니다. + */ + public void emptyOutUserInfo() { + this.name = ""; + this.phone = ""; + this.nickname = ""; + this.password = ""; + } } diff --git a/src/main/java/com/taba/nimonaemo/member/service/SignupService.java b/src/main/java/com/taba/nimonaemo/member/service/SignupService.java index 8dccfa4..e2d6ba8 100644 --- a/src/main/java/com/taba/nimonaemo/member/service/SignupService.java +++ b/src/main/java/com/taba/nimonaemo/member/service/SignupService.java @@ -9,6 +9,7 @@ import com.taba.nimonaemo.member.model.dto.response.ResponseSignupTokenDto; import com.taba.nimonaemo.member.model.entity.Member; import com.taba.nimonaemo.member.repository.MemberRepository; +import com.taba.nimonaemo.record.exception.HairStatusNotFoundException; import com.taba.nimonaemo.record.model.entity.HairStatus; import com.taba.nimonaemo.record.repository.HairStatusRepository; import lombok.RequiredArgsConstructor; @@ -39,23 +40,34 @@ public void signup(RequestSignupDto dto, String signupToken) { String phone = smsVerificationService.getPhoneNumber(signupToken); String encryptedPassword = passwordEncoder.encode(dto.getPassword()); -// Optional inactiveUser = userRepository.findByInactiveByNickname(dto.getNickname()); - //TODO 회원탈퇴 로직이 필요할 시 구현 - - Member member = Member.builder() - .name(dto.getName()) - .nickname(dto.getNickname()) - .password(encryptedPassword) - .phone(phone) - .memberRole(MemberRole.MEMBER) - .status(MemberStatus.ACTIVE) - .build(); - memberRepository.save(member); - - HairStatus hairStatus = HairStatus.builder() - .member(member) - .build(); - hairStatusRepository.save(hairStatus); + Optional inactiveUser = memberRepository.findByInactiveByPhone(dto.getPhone()); + + if (inactiveUser.isPresent()) { + Member member = inactiveUser.get(); + member.changeStatus(MemberStatus.ACTIVE); + member.changeName(dto.getName()); + member.changeNickname(dto.getNickname()); + + HairStatus hairStatus = hairStatusRepository.findByMemberId(member.getId()).orElseThrow(HairStatusNotFoundException::new); + hairStatus.changeStartPermDate(null); + hairStatus.changeStartDyeDate(null); + } + else { + Member member = Member.builder() + .name(dto.getName()) + .nickname(dto.getNickname()) + .password(encryptedPassword) + .phone(phone) + .memberRole(MemberRole.MEMBER) + .status(MemberStatus.ACTIVE) + .build(); + memberRepository.save(member); + + HairStatus hairStatus = HairStatus.builder() + .member(member) + .build(); + hairStatusRepository.save(hairStatus); + } deleteSignupAuths(signupToken); }