From eca7797aa24ac56921230a6ad2ca0945c236662f Mon Sep 17 00:00:00 2001 From: minsu20 Date: Sat, 18 Nov 2023 16:29:02 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20member=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=95=A0=20=EB=95=8C=20=EC=86=8C=ED=94=84=ED=8A=B8=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/domain/entity/Member.java | 18 +++++++++++++++--- .../teamMember/domain/entity/TeamMember.java | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/member/domain/entity/Member.java b/src/main/java/com/moing/backend/domain/member/domain/entity/Member.java index 5d4fa4b9..ca87d769 100644 --- a/src/main/java/com/moing/backend/domain/member/domain/entity/Member.java +++ b/src/main/java/com/moing/backend/domain/member/domain/entity/Member.java @@ -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; @@ -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) @@ -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; @@ -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) @@ -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 teamMembers = new ArrayList<>(); //최대 3개이므로 양방향 @@ -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; @@ -154,4 +162,8 @@ public Member(LocalDate birthDate, String email, String fcmToken, Gender gender, this.socialId = socialId; } + public void deleteMember(){ + this.isDeleted=true; + } + } diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/entity/TeamMember.java b/src/main/java/com/moing/backend/domain/teamMember/domain/entity/TeamMember.java index 9769d51f..5cf9ffea 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/entity/TeamMember.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/entity/TeamMember.java @@ -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) { From 6d39adc787efc80007130a86922b1dff131d3012 Mon Sep 17 00:00:00 2001 From: minsu20 Date: Sat, 18 Nov 2023 16:29:25 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20member=EC=A1=B0=ED=9A=8C=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C=20=EC=82=AD=EC=A0=9C=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=80=20member=EC=A1=B0=ED=9A=8C=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/MemberCustomRepository.java | 4 ++++ .../MemberCustomRepositoryImpl.java | 19 +++++++++++++++++++ .../domain/repository/MemberRepository.java | 4 ---- .../domain/service/MemberGetService.java | 2 +- .../domain/service/MemberSaveService.java | 4 +++- .../application/service/WithdrawUserCase.java | 5 ++--- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepository.java b/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepository.java index c1b27c23..03f785ca 100644 --- a/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepository.java @@ -6,4 +6,8 @@ public interface MemberCustomRepository { boolean checkNickname(String nickname); + + Optional findNotDeletedBySocialId(String socialId); + + Optional findNotDeletedByEmail(String email); } diff --git a/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepositoryImpl.java index 2126f3b1..0149fdcc 100644 --- a/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepositoryImpl.java @@ -22,6 +22,25 @@ public boolean checkNickname(String nickname) { .selectOne() .from(member) .where(member.nickName.eq(nickname)) + .where(member.isDeleted.eq(false)) .fetchFirst() != null; } + + @Override + public Optional findNotDeletedBySocialId(String socialId) { + return Optional.ofNullable(queryFactory + .selectFrom(member) + .where(member.socialId.eq(socialId)) + .where(member.isDeleted.eq(false)) + .fetchOne()); + } + + @Override + public Optional findNotDeletedByEmail(String email) { + return Optional.ofNullable(queryFactory + .selectFrom(member) + .where(member.email.eq(email)) + .where(member.isDeleted.eq(false)) + .fetchOne()); + } } diff --git a/src/main/java/com/moing/backend/domain/member/domain/repository/MemberRepository.java b/src/main/java/com/moing/backend/domain/member/domain/repository/MemberRepository.java index 20cb1f23..694e75df 100644 --- a/src/main/java/com/moing/backend/domain/member/domain/repository/MemberRepository.java +++ b/src/main/java/com/moing/backend/domain/member/domain/repository/MemberRepository.java @@ -7,8 +7,4 @@ public interface MemberRepository extends JpaRepository, MemberCustomRepository { - Optional findBySocialId(String socialId); - - Optional findByEmail(String email); - } diff --git a/src/main/java/com/moing/backend/domain/member/domain/service/MemberGetService.java b/src/main/java/com/moing/backend/domain/member/domain/service/MemberGetService.java index dc88284d..31dc3a07 100644 --- a/src/main/java/com/moing/backend/domain/member/domain/service/MemberGetService.java +++ b/src/main/java/com/moing/backend/domain/member/domain/service/MemberGetService.java @@ -15,6 +15,6 @@ 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()); } } diff --git a/src/main/java/com/moing/backend/domain/member/domain/service/MemberSaveService.java b/src/main/java/com/moing/backend/domain/member/domain/service/MemberSaveService.java index ca6480f0..2332f2f7 100644 --- a/src/main/java/com/moing/backend/domain/member/domain/service/MemberSaveService.java +++ b/src/main/java/com/moing/backend/domain/member/domain/service/MemberSaveService.java @@ -6,6 +6,7 @@ import lombok.AllArgsConstructor; import javax.transaction.Transactional; +import java.time.LocalDateTime; import java.util.Optional; @DomainService @@ -16,11 +17,12 @@ public class MemberSaveService { private final MemberRepository memberRepository; public Member saveMember(Member member) { - OptionalfindMember=memberRepository.findByEmail(member.getEmail()); + OptionalfindMember=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(); } } diff --git a/src/main/java/com/moing/backend/domain/mypage/application/service/WithdrawUserCase.java b/src/main/java/com/moing/backend/domain/mypage/application/service/WithdrawUserCase.java index cf693283..02ee59dc 100644 --- a/src/main/java/com/moing/backend/domain/mypage/application/service/WithdrawUserCase.java +++ b/src/main/java/com/moing/backend/domain/mypage/application/service/WithdrawUserCase.java @@ -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; @@ -24,8 +25,6 @@ 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 withdrawProviders; @@ -33,7 +32,7 @@ public void withdraw(String socialId, String providerInfo, WithdrawRequest withd Member member = memberGetService.getMemberBySocialId(socialId); checkMemberIsNotPartOfAnyTeam(member); withdraw(providerInfo, withdrawRequest.getSocialToken()); - memberDeleteService.deleteMember(member); + member.deleteMember(); feedbackSaveService.saveFeedback(member, withdrawRequest); tokenUtil.expireRefreshToken(socialId); } From cfc0748e915a53b6ae1f8a38147a16174b455f38 Mon Sep 17 00:00:00 2001 From: minsu20 Date: Sat, 18 Nov 2023 16:33:14 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20member=EC=A1=B0=ED=9A=8C=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C=20=EC=82=AD=EC=A0=9C=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=80=20member=20=EC=A1=B0=ED=9A=8C=ED=95=98=EA=B2=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/domain/repository/MemberCustomRepository.java | 1 + .../domain/repository/MemberCustomRepositoryImpl.java | 9 +++++++++ .../domain/member/domain/service/MemberGetService.java | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepository.java b/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepository.java index 03f785ca..3f8ab192 100644 --- a/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepository.java @@ -10,4 +10,5 @@ public interface MemberCustomRepository { Optional findNotDeletedBySocialId(String socialId); Optional findNotDeletedByEmail(String email); + Optional findNotDeletedByMemberId(Long id); } diff --git a/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepositoryImpl.java index 0149fdcc..9c841321 100644 --- a/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/member/domain/repository/MemberCustomRepositoryImpl.java @@ -43,4 +43,13 @@ public Optional findNotDeletedByEmail(String email) { .where(member.isDeleted.eq(false)) .fetchOne()); } + + @Override + public Optional findNotDeletedByMemberId(Long id) { + return Optional.ofNullable(queryFactory + .selectFrom(member) + .where(member.memberId.eq(id)) + .where(member.isDeleted.eq(false)) + .fetchOne()); + } } diff --git a/src/main/java/com/moing/backend/domain/member/domain/service/MemberGetService.java b/src/main/java/com/moing/backend/domain/member/domain/service/MemberGetService.java index 33dab9ef..8c78c8b8 100644 --- a/src/main/java/com/moing/backend/domain/member/domain/service/MemberGetService.java +++ b/src/main/java/com/moing/backend/domain/member/domain/service/MemberGetService.java @@ -19,6 +19,6 @@ public Member getMemberBySocialId(String socialId){ } public Member getMemberByMemberId(Long memberId) { - return memberRepository.findByMemberId(memberId).orElseThrow(()->new NotFoundBySocialIdException()); + return memberRepository.findNotDeletedByMemberId(memberId).orElseThrow(()->new NotFoundBySocialIdException()); } }