Skip to content

Commit

Permalink
feat: 회원 탈퇴 후(휴면 계정 상태), 다시 회원가입한 멤버에 대한 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kjungw1025 committed Dec 16, 2023
1 parent 0a71f94 commit 19ec3fa
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 17 deletions.
54 changes: 54 additions & 0 deletions src/main/java/com/taba/nimonaemo/member/model/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseEntity {

public static String DELETED_MEMBER = "탈퇴한 회원";

@Id
@GeneratedValue
@Column(name = "member_id")
Expand Down Expand Up @@ -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 = "";
}
}
46 changes: 29 additions & 17 deletions src/main/java/com/taba/nimonaemo/member/service/SignupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,23 +40,34 @@ public void signup(RequestSignupDto dto, String signupToken) {
String phone = smsVerificationService.getPhoneNumber(signupToken);
String encryptedPassword = passwordEncoder.encode(dto.getPassword());

// Optional<User> 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<Member> 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);
}
Expand Down

0 comments on commit 19ec3fa

Please sign in to comment.