Skip to content

Commit

Permalink
feat: add member-status column
Browse files Browse the repository at this point in the history
  • Loading branch information
IW-MOON committed May 7, 2023
1 parent 5c5d3cf commit 75758fa
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 16 deletions.
3 changes: 2 additions & 1 deletion module-api/src/main/java/inspiration/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import inspiration.auth.request.LoginRequest;
import inspiration.domain.member.Member;
import inspiration.domain.member.MemberRepository;
import inspiration.domain.member.MemberStatus;
import inspiration.domain.member.response.MemberInfoResponse;
import inspiration.enumeration.ExceptionType;
import inspiration.enumeration.ExpireTimeConstants;
Expand Down Expand Up @@ -44,7 +45,7 @@ public ResultResponse<TokenResponse> login(LoginRequest request) {
}

private Member checkEmail(String email) {
return memberRepository.findByEmailAndStatusIsNull(email)
return memberRepository.findByEmailAndMemberStatus(email, MemberStatus.REGISTERED)
.orElseThrow(() -> new PostNotFoundException(ExceptionType.EMAIl_NOT_FOUND.getMessage()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package inspiration.domain.emailauth;

import inspiration.ResultResponse;
import inspiration.domain.member.MemberStatus;
import inspiration.enumeration.ExceptionType;
import inspiration.exception.PostNotFoundException;
import inspiration.domain.member.MemberRepository;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void authenticateEmailOfSignUp(String email) {
@Transactional
public void resetPasswordForAuthEmailSend(String email) {

if (!memberRepository.existsByEmailAndStatusIsNull(email)) {
if (!memberRepository.existsByEmailAndMemberStatus(email, MemberStatus.REGISTERED)) {
throw new PostNotFoundException(ExceptionType.MEMBER_NOT_FOUND.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void changePassword(Long memberId, String confirmPassword, String passwor
@Transactional
public void resetPasswordEmailSend(String email) {

Member member = memberRepository.findByEmailAndStatusIsNull(email)
Member member = memberRepository.findByEmailAndMemberStatus(email, MemberStatus.REGISTERED)
.orElseThrow(() -> new PostNotFoundException(ExceptionType.USER_NOT_EXISTS.getMessage()));

String resetPassword = GetResetPasswordUtil.getResetPassword();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import inspiration.auth.jwt.JwtProvider;
import inspiration.auth.TokenResponse;
import inspiration.domain.emailauth.EmailAuthRepository;
import inspiration.domain.member.MemberStatus;
import inspiration.enumeration.ExceptionType;
import inspiration.exception.ConflictRequestException;
import inspiration.exception.PostNotFoundException;
Expand Down Expand Up @@ -51,15 +52,15 @@ public ResultResponse checkNickName(String nickname) {
@Transactional
public void updateExtraInfo(String email, ExtraInfoRequest request) {

Member member = memberRepository.findByEmailAndStatusIsNull(email)
Member member = memberRepository.findByEmailAndMemberStatus(email, MemberStatus.REGISTERED)
.orElseThrow(() -> new PostNotFoundException(ExceptionType.USER_NOT_EXISTS.getMessage()));

member.updateExtraInfo(request.getGender(), request.getAge(), request.getJob());
}

public ResultResponse validSignUpEmailStatus(String email) {

if (memberRepository.existsByEmailAndStatusIsNull(email)) {
if (memberRepository.existsByEmailAndMemberStatus(email, MemberStatus.REGISTERED)) {

return ResultResponse.of(ExceptionType.EMAIL_ALREADY_AUTHENTICATED.getMessage(), true);
}
Expand All @@ -83,14 +84,14 @@ private void verifyEmail(String email) {

private void isValidNickName(String nickName) {

if (memberRepository.existsByNicknameAndStatusIsNull(nickName)) {
if (memberRepository.existsByNicknameAndMemberStatus(nickName, MemberStatus.REGISTERED)) {
throw new ConflictRequestException(ExceptionType.EXISTS_NICKNAME.getMessage());
}
}

private void isValidEmail(String email) {

if (memberRepository.existsByEmailAndStatusIsNull(email)) {
if (memberRepository.existsByEmailAndMemberStatus(email, MemberStatus.REGISTERED)) {
throw new ConflictRequestException(ExceptionType.EXISTS_EMAIL.getMessage());
}
}
Expand Down
19 changes: 15 additions & 4 deletions module-domain/src/main/java/inspiration/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
@Getter
@Entity
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString(callSuper = true)
public class Member extends BaseTimeEntity {
Expand Down Expand Up @@ -39,8 +38,20 @@ public class Member extends BaseTimeEntity {
@Column(nullable = true)
private String job;

@Column(nullable = true, length = 1)
private Integer status;
@Enumerated(value = EnumType.STRING)
private MemberStatus memberStatus;


private Member(Long id, String nickname, String email, String password, GenderType gender, AgeGroupType age_group, String job, MemberStatus memberStatus) {
this.id = id;
this.nickname = nickname;
this.email = email;
this.password = password;
this.gender = gender;
this.age_group = age_group;
this.job = job;
this.memberStatus = MemberStatus.REGISTERED;
}

public void updatePassword(String password) {

Expand All @@ -64,6 +75,6 @@ public boolean isSameMember(Long id) {
}

public void removeMember(){
this.status = 1;
this.memberStatus = MemberStatus.UNREGISTERED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

public interface MemberRepository extends JpaRepository<Member, Long>, MemberRepositoryCustom {

Optional<Member> findByEmailAndStatusIsNull(String email);
Optional<Member> findByEmailAndMemberStatus(String email, MemberStatus memberStatus);

boolean existsByNicknameAndStatusIsNull(String nickName);
boolean existsByNicknameAndMemberStatus(String nickName, MemberStatus memberStatus);

boolean existsByEmailAndStatusIsNull(String email);
boolean existsByEmailAndMemberStatus(String email, MemberStatus memberStatus);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package inspiration.domain.member;

public enum MemberStatus {
REGISTERED, UNREGISTERED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table member
add column member_status varchar(255)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
alter table member
add column status integer ;
add column member_status varchar(255)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import inspiration.domain.emailauth.request.SendEmailRequest;
import inspiration.domain.member.Member;
import inspiration.domain.member.MemberRepository;
import inspiration.domain.member.MemberStatus;
import inspiration.domain.member.request.SignUpRequest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -70,7 +71,7 @@ void signUp() throws Exception {
// then 1
.andExpect(status().isCreated());
// then 2
Optional<Member> member = memberRepository.findByEmailAndStatusIsNull(email);
Optional<Member> member = memberRepository.findByEmailAndMemberStatus(email, MemberStatus.REGISTERED);
assertThat(member).isPresent();
assertThat(member.get().getEmail()).isEqualTo(email);
assertThat(member.get().getNickname()).isEqualTo("nickname");
Expand Down

0 comments on commit 75758fa

Please sign in to comment.