Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: member 상태관리를 위한 member.status 추가에 따른 수정 #200

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.findByEmail(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 @@ -46,7 +47,7 @@ public void authenticateEmailOfSignUp(String email) {
@Transactional
public void resetPasswordForAuthEmailSend(String email) {

if (!memberRepository.existsByEmail(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.findByEmail(email)
Member member = memberRepository.findByEmailAndMemberStatus(email, MemberStatus.REGISTERED)
.orElseThrow(() -> new PostNotFoundException(ExceptionType.USER_NOT_EXISTS.getMessage()));

String resetPassword = GetResetPasswordUtil.getResetPassword();
Expand Down Expand Up @@ -72,9 +72,7 @@ public void removeUser(Long memberId) {
.orElseThrow(() -> new PostNotFoundException(ExceptionType.USER_NOT_EXISTS.getMessage()));

emailAuthRepository.deleteByEmail(member.getEmail());

memberRepository.deleteById(memberId);

member.removeMember();
}

private void confirmPasswordCheck(String confirmPasswordCheck, String password) {
Expand All @@ -89,11 +87,4 @@ public Member findById(Long id) {
.orElseThrow(UnauthorizedAccessRequestException::new);
}

public List<MemberResponse> findAll() {
return memberRepository.findAll()
.stream()
.map(MemberResponse::of)
.collect(Collectors.toList());
}

}
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.findByEmail(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.existsByEmail(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.existsByNickname(nickName)) {
if (memberRepository.existsByNicknameAndMemberStatus(nickName, MemberStatus.REGISTERED)) {
throw new ConflictRequestException(ExceptionType.EXISTS_NICKNAME.getMessage());
}
}

private void isValidEmail(String email) {

if (memberRepository.existsByEmail(email)) {
if (memberRepository.existsByEmailAndMemberStatus(email, MemberStatus.REGISTERED)) {
throw new ConflictRequestException(ExceptionType.EXISTS_EMAIL.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package inspiration.domain.inspiration;

import inspiration.domain.member.Member;
import inspiration.domain.tag.Tag;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -21,14 +20,9 @@ public interface InspirationRepository extends JpaRepository<Inspiration, Long>,

Optional<Inspiration> findAllByMemberAndId(Member member, Long id);

@Query(value = "select it.inspiration from InspirationTag it where it.tag in :tags group by it.inspiration having count(it.inspiration) >= :count")
Optional<List<Inspiration>> findDistinctInspirationByTags(@Param("tags") List<Tag> tags, @Param("count") Long count);

Page<Inspiration> findAllByIdIn(List<Long> inspirationIds, Pageable pageable);

List<Inspiration> findAllByMember(Member member);

@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query(value = "delete from Inspiration i where i.member = :member")
void deleteAllByMember(Member member);
void deleteAllByMember(@Param("member") Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;
Expand All @@ -18,7 +19,7 @@ public interface InspirationTagRepository extends JpaRepository<InspirationTag,

@Modifying
@Query(value = "delete from InspirationTag where inspiration in :inspirations")
void deleteAllByInspirationIn(List<Inspiration> inspirations);
void deleteAllByInspirationIn(@Param("inspirations") List<Inspiration> inspirations);

void deleteAllByTag(Tag tag);

Expand Down
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 @@ -37,11 +36,25 @@ public class Member extends BaseTimeEntity {
*/
@Column
@Enumerated(EnumType.STRING)
private AgeGroupType ageGroup;
private AgeGroupType ageGroupType;

@Column
private String job;

@Enumerated(value = EnumType.STRING)
private MemberStatus memberStatus;

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

public void updatePassword(String password) {

this.password = password;
Expand All @@ -52,14 +65,18 @@ public void updateNickname(String nickname) {
this.nickname = nickname;
}

public void updateExtraInfo(GenderType gender, AgeGroupType ageGroup, String job) {
public void updateExtraInfo(GenderType gender, AgeGroupType ageGroupType, String job) {

this.gender = gender;
this.ageGroup = ageGroup;
this.ageGroupType = ageGroupType;
this.job = job;
}

public boolean isSameMember(Long id) {
return this.id.equals(id);
}

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

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

Optional<Member> findById(Long id);
Optional<Member> findByEmailAndMemberStatus(String email, MemberStatus memberStatus);

Optional<Member> findByEmail(String email);
boolean existsByNicknameAndMemberStatus(String nickName, MemberStatus memberStatus);

boolean existsByNickname(String nickName);
boolean existsByEmailAndMemberStatus(String email, MemberStatus memberStatus);

boolean existsByEmail(String email);
}
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
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;
Expand All @@ -26,6 +27,6 @@ public interface TagRepository extends JpaRepository<Tag, Long>{

@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query(value = "delete from Tag t where t.member = :member")
void deleteAllByMember(Member member);
void deleteAllByMember(@Param("member") Member member);

}
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
@@ -0,0 +1,2 @@
alter table member
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flyway 거의 신경 못쓰고있었는데 감사합니다 👍

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.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -70,7 +71,7 @@ void signUp() throws Exception {
// then 1
.andExpect(status().isCreated());
// then 2
Optional<Member> member = memberRepository.findByEmail(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