From d71af4e2e07ca27e8fa4588e9ca0a710bd3c0da5 Mon Sep 17 00:00:00 2001 From: junwon <67488973+wjdwnsdnjs13@users.noreply.github.com> Date: Sun, 21 Jul 2024 16:36:47 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EB=A9=A4=EB=B2=84=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=EA=B5=AC=ED=98=84=20(#64)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 15 +++++++++++++++ .../member/repository/MemberJpaRepository.java | 2 ++ .../member/repository/MemberRepositoryImpl.java | 5 +++++ .../usecase/port/in/member/MemberUsecase.java | 2 ++ .../usecase/port/out/member/MemberRepository.java | 2 ++ .../usecase/service/member/MemberService.java | 15 +++++++++++++++ 6 files changed, 41 insertions(+) diff --git a/application/src/main/java/org/depromeet/spot/application/member/controller/MemberController.java b/application/src/main/java/org/depromeet/spot/application/member/controller/MemberController.java index 2bc5cdba..95ba54ec 100644 --- a/application/src/main/java/org/depromeet/spot/application/member/controller/MemberController.java +++ b/application/src/main/java/org/depromeet/spot/application/member/controller/MemberController.java @@ -8,6 +8,7 @@ import org.depromeet.spot.domain.member.Member; import org.depromeet.spot.usecase.port.in.member.MemberUsecase; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -82,4 +83,18 @@ public String getAccessToken( String idCode) { return memberUsecase.getAccessToken(idCode); } + + @DeleteMapping("/{accessToken}") + @ResponseStatus(HttpStatus.OK) + @Operation(summary = "(개발용) Member 삭제 API") + public Boolean deleteMember( + @PathVariable("accessToken") + @Parameter( + name = "accessToken", + description = "sns accessToken", + required = true) + String accessToken) { + // TODO : (개발용) 유저 탈퇴 아님! 단순 유저 삭제만 진행함. + return memberUsecase.deleteMember(accessToken); + } } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/repository/MemberJpaRepository.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/repository/MemberJpaRepository.java index 2333d318..c6d6be52 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/repository/MemberJpaRepository.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/repository/MemberJpaRepository.java @@ -25,4 +25,6 @@ void updateProfile( @Param("profileImage") String profileImage, @Param("teamId") Long teamId, @Param("nickname") String nickname); + + void deleteByIdToken(String idToken); } diff --git a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/repository/MemberRepositoryImpl.java b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/repository/MemberRepositoryImpl.java index c70e82bd..70c6c858 100644 --- a/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/repository/MemberRepositoryImpl.java +++ b/infrastructure/jpa/src/main/java/org/depromeet/spot/jpa/member/repository/MemberRepositoryImpl.java @@ -45,4 +45,9 @@ public Member findById(Long memberId) { memberJpaRepository.findById(memberId).orElseThrow(MemberNotFoundException::new); return entity.toDomain(); } + + @Override + public void deleteByIdToken(String idToken) { + memberJpaRepository.deleteByIdToken(idToken); + } } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/MemberUsecase.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/MemberUsecase.java index b34d5100..e4308a59 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/MemberUsecase.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/member/MemberUsecase.java @@ -11,4 +11,6 @@ public interface MemberUsecase { Boolean duplicatedNickname(String nickname); String getAccessToken(String idCode); + + Boolean deleteMember(String accessToken); } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/out/member/MemberRepository.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/out/member/MemberRepository.java index 496f0300..7b33e867 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/out/member/MemberRepository.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/out/member/MemberRepository.java @@ -15,4 +15,6 @@ public interface MemberRepository { Boolean existsByNickname(String nickname); Member findById(Long memberId); + + void deleteByIdToken(String idToken); } diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/service/member/MemberService.java b/usecase/src/main/java/org/depromeet/spot/usecase/service/member/MemberService.java index cd1cecf3..9a43b2ed 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/service/member/MemberService.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/service/member/MemberService.java @@ -3,11 +3,13 @@ import java.util.Optional; import org.depromeet.spot.common.exception.member.MemberException.MemberNicknameConflictException; +import org.depromeet.spot.common.exception.member.MemberException.MemberNotFoundException; import org.depromeet.spot.domain.member.Member; import org.depromeet.spot.usecase.port.in.member.MemberUsecase; import org.depromeet.spot.usecase.port.out.member.MemberRepository; import org.depromeet.spot.usecase.port.out.oauth.OauthRepository; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; @@ -56,4 +58,17 @@ public Boolean duplicatedNickname(String nickname) { public String getAccessToken(String idCode) { return oauthRepository.getKakaoAccessToken(idCode); } + + @Transactional + @Override + public Boolean deleteMember(String accessToken) { + Member memberResult = oauthRepository.getLoginUserInfo(accessToken); + Optional existedMember = memberRepository.findByIdToken(memberResult.getIdToken()); + // 멤버 없으면 오류 출력 + if (existedMember.isEmpty()) { + throw new MemberNotFoundException(); + } + memberRepository.deleteByIdToken(memberResult.getIdToken()); + return Boolean.TRUE; + } }