From 6f1857f54585258eb1a6d6b02ca3b2b4ca8996c0 Mon Sep 17 00:00:00 2001 From: kjungw1025 Date: Sat, 16 Dec 2023 13:30:37 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=ED=83=88=ED=87=B4?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/UserController.java | 17 +++++++------- .../member/repository/MemberRepository.java | 3 +++ .../member/service/MemberWithdrawService.java | 22 +++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/taba/nimonaemo/member/service/MemberWithdrawService.java diff --git a/src/main/java/com/taba/nimonaemo/member/controller/UserController.java b/src/main/java/com/taba/nimonaemo/member/controller/UserController.java index 0563523..53bce94 100644 --- a/src/main/java/com/taba/nimonaemo/member/controller/UserController.java +++ b/src/main/java/com/taba/nimonaemo/member/controller/UserController.java @@ -101,12 +101,13 @@ public ResponseMemberInfoDto getMemberInfo(AppAuthentication auth) { return memberService.getMemberInfo(auth.getUserId()); } -// /** -// * 회원탈퇴 -// *

회원은 바로 삭제되지 않고, 일정 기간 뒤에 삭제됩니다. 삭제시에도 개인 정보만 삭제됩니다.

-// */ -// @DeleteMapping -// public void withdraw(AppAuthentication auth) { -// memberWithdrawService.withdraw(auth.getUserId()); -// } + /** + * 회원탈퇴 + *

회원은 바로 삭제되지 않고(비활성화로 전환), 일정 기간 뒤에 삭제됩니다.

+ */ + @DeleteMapping + @MemberAuth + public void withdraw(AppAuthentication auth) { + memberWithdrawService.withdraw(auth.getUserId()); + } } diff --git a/src/main/java/com/taba/nimonaemo/member/repository/MemberRepository.java b/src/main/java/com/taba/nimonaemo/member/repository/MemberRepository.java index 5ad7313..216498f 100644 --- a/src/main/java/com/taba/nimonaemo/member/repository/MemberRepository.java +++ b/src/main/java/com/taba/nimonaemo/member/repository/MemberRepository.java @@ -21,4 +21,7 @@ public interface MemberRepository extends JpaRepository , JpaSpeci @Query("select m from Member m where m.status = 'ACTIVE' and m.name = :name") Optional findByName(String name); + + @Query("select m from Member m where m.status = 'INACTIVE' and m.phone = :phone") + Optional findByInactiveByPhone(String phone); } diff --git a/src/main/java/com/taba/nimonaemo/member/service/MemberWithdrawService.java b/src/main/java/com/taba/nimonaemo/member/service/MemberWithdrawService.java new file mode 100644 index 0000000..1d74b97 --- /dev/null +++ b/src/main/java/com/taba/nimonaemo/member/service/MemberWithdrawService.java @@ -0,0 +1,22 @@ +package com.taba.nimonaemo.member.service; + +import com.taba.nimonaemo.member.exception.UserNotFoundException; +import com.taba.nimonaemo.member.model.MemberStatus; +import com.taba.nimonaemo.member.model.entity.Member; +import com.taba.nimonaemo.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class MemberWithdrawService { + private final MemberRepository memberRepository; + + @Transactional + public void withdraw(Long userId) { + Member member = memberRepository.findById(userId).orElseThrow(UserNotFoundException::new); + member.changeStatus(MemberStatus.INACTIVE); + } +}