Skip to content

Commit

Permalink
Merge pull request #80 from Modagbul/fix/auth
Browse files Browse the repository at this point in the history
member삭제 오류 해결
  • Loading branch information
minsu20 authored Nov 18, 2023
2 parents 32a7839 + cfc0748 commit 82c2d26
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -32,7 +33,7 @@ public class Member extends BaseTimeEntity {
@Column(name = "member_id")
private Long memberId;

@Column(nullable = false, unique = true)
@Column(nullable = false)
private String socialId;

@Enumerated(EnumType.STRING)
Expand All @@ -44,7 +45,7 @@ public class Member extends BaseTimeEntity {
private RegistrationStatus registrationStatus;

@Convert(converter = AesConverter.class)
@Column(nullable = false, unique = true)
@Column(nullable = false)
private String email;

private String profileImage;
Expand All @@ -56,7 +57,6 @@ public class Member extends BaseTimeEntity {
private LocalDate birthDate;

@Convert(converter = AesConverter.class)
@Column(unique=true)
private String nickName;

@Column(nullable = false)
Expand All @@ -79,6 +79,10 @@ public class Member extends BaseTimeEntity {
@Column(nullable = false)
private boolean isFirePush;

private boolean isDeleted;

private LocalDateTime lastSignInTime;

@OneToMany(mappedBy = "member")
private List<TeamMember> teamMembers = new ArrayList<>(); //최대 3개이므로 양방향

Expand Down Expand Up @@ -140,6 +144,10 @@ public void updateFcmToken(String fcmToken) {
this.fcmToken = fcmToken;
}

public void updateLastSignInTime(LocalDateTime time){
this.lastSignInTime=time;
}

public Member(LocalDate birthDate, String email, String fcmToken, Gender gender, String introduction, String nickName, String profileImage, SocialProvider provider, RegistrationStatus registrationStatus, Role role, String socialId) {
this.birthDate = birthDate;
this.email = email;
Expand All @@ -154,4 +162,8 @@ public Member(LocalDate birthDate, String email, String fcmToken, Gender gender,
this.socialId = socialId;
}

public void deleteMember(){
this.isDeleted=true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@

public interface MemberCustomRepository {
boolean checkNickname(String nickname);

Optional<Member> findNotDeletedBySocialId(String socialId);

Optional<Member> findNotDeletedByEmail(String email);
Optional<Member> findNotDeletedByMemberId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@ public boolean checkNickname(String nickname) {
.selectOne()
.from(member)
.where(member.nickName.eq(nickname))
.where(member.isDeleted.eq(false))
.fetchFirst() != null;
}

@Override
public Optional<Member> findNotDeletedBySocialId(String socialId) {
return Optional.ofNullable(queryFactory
.selectFrom(member)
.where(member.socialId.eq(socialId))
.where(member.isDeleted.eq(false))
.fetchOne());
}

@Override
public Optional<Member> findNotDeletedByEmail(String email) {
return Optional.ofNullable(queryFactory
.selectFrom(member)
.where(member.email.eq(email))
.where(member.isDeleted.eq(false))
.fetchOne());
}

@Override
public Optional<Member> findNotDeletedByMemberId(Long id) {
return Optional.ofNullable(queryFactory
.selectFrom(member)
.where(member.memberId.eq(id))
.where(member.isDeleted.eq(false))
.fetchOne());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,4 @@
import java.util.Optional;

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

Optional<Member> findBySocialId(String socialId);

Optional<Member> findByEmail(String email);

Optional<Member> findByMemberId(Long id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class MemberGetService {
private final MemberRepository memberRepository;

public Member getMemberBySocialId(String socialId){
return memberRepository.findBySocialId(socialId).orElseThrow(()->new NotFoundBySocialIdException());
return memberRepository.findNotDeletedBySocialId(socialId).orElseThrow(()->new NotFoundBySocialIdException());
}

public Member getMemberByMemberId(Long memberId) {
return memberRepository.findByMemberId(memberId).orElseThrow(()->new NotFoundBySocialIdException());
return memberRepository.findNotDeletedByMemberId(memberId).orElseThrow(()->new NotFoundBySocialIdException());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.AllArgsConstructor;

import javax.transaction.Transactional;
import java.time.LocalDateTime;
import java.util.Optional;

@DomainService
Expand All @@ -16,11 +17,12 @@ public class MemberSaveService {
private final MemberRepository memberRepository;

public Member saveMember(Member member) {
Optional<Member>findMember=memberRepository.findByEmail(member.getEmail());
Optional<Member>findMember=memberRepository.findNotDeletedByEmail(member.getEmail());
if(findMember.isEmpty()){
return memberRepository.save(member);
} else {
findMember.get().updateFcmToken(member.getFcmToken());
findMember.get().updateLastSignInTime(LocalDateTime.now());
return findMember.get();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.moing.backend.domain.mypage.domain.service.FeedbackSaveService;
import com.moing.backend.domain.mypage.exception.ExistingTeamException;
import com.moing.backend.domain.team.domain.service.TeamGetService;
import com.moing.backend.domain.teamMember.domain.entity.TeamMember;
import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService;
import com.moing.backend.global.config.security.jwt.TokenUtil;
import lombok.RequiredArgsConstructor;
Expand All @@ -24,16 +25,14 @@ public class WithdrawUserCase {
private final MemberGetService memberGetService;
private final FeedbackSaveService feedbackSaveService;
private final TokenUtil tokenUtil;
private final MemberDeleteService memberDeleteService;
private final TeamMemberGetService teamMemberGetService;
private final TeamGetService teamGetService;
private final Map<String, WithdrawProvider> withdrawProviders;

public void withdraw(String socialId, String providerInfo, WithdrawRequest withdrawRequest) throws IOException {
Member member = memberGetService.getMemberBySocialId(socialId);
checkMemberIsNotPartOfAnyTeam(member);
withdraw(providerInfo, withdrawRequest.getSocialToken());
memberDeleteService.deleteMember(member);
member.deleteMember();
feedbackSaveService.saveFeedback(member, withdrawRequest);
tokenUtil.expireRefreshToken(socialId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public void updateTeam(Team team) {

public void updateMember(Member member) {
this.member = member;
member.getTeamMembers().add(this);
if (member != null) {
member.getTeamMembers().add(this);
}
}

public void deleteMember(Team team) {
Expand Down

0 comments on commit 82c2d26

Please sign in to comment.