From 2cc65d4c5ae3c68c7b8a7aaf16a31fa47188508e Mon Sep 17 00:00:00 2001 From: arinming Date: Wed, 14 Feb 2024 21:10:31 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20service=EB=A1=9C=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=ED=83=88=ED=87=B4=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20updateSta?= =?UTF-8?q?tus=20=EA=B5=AC=ED=98=84=20(#60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/application/MemberService.java | 20 ++-------- .../ttubeog/domain/member/domain/Member.java | 5 --- .../domain/repository/MemberRepository.java | 3 ++ .../member/presentation/MemberController.java | 37 ++++++------------- 4 files changed, 18 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/member/application/MemberService.java b/src/main/java/com/ttubeog/domain/member/application/MemberService.java index 26c6b8bc..6916a276 100644 --- a/src/main/java/com/ttubeog/domain/member/application/MemberService.java +++ b/src/main/java/com/ttubeog/domain/member/application/MemberService.java @@ -25,8 +25,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; +import java.util.concurrent.TimeUnit; @RequiredArgsConstructor @Service @@ -181,7 +183,7 @@ public void deleteValueByKey(String key) { } @Transactional - public ResponseEntity deleteUser(HttpServletRequest request) { + public ResponseEntity deleteMember(HttpServletRequest request) { Long memberId = jwtTokenProvider.getMemberId(request); Optional checkMember = memberRepository.findById(memberId); @@ -189,21 +191,7 @@ public ResponseEntity deleteUser(HttpServletRequest request) { throw new InvalidMemberException(); } - Member member = checkMember.get(); - if (member.getStatus() != Status.INACTIVE) { - member = Member.builder() - .id(member.getId()) - .oAuthId(member.getOAuthId()) - .nickname(member.getNickname()) - .memberNumber(member.getMemberNumber()) - .email(member.getEmail()) - .platformId(member.getPlatformId()) - .platform(member.getPlatform()) - .status(Status.INACTIVE) // 상태를 비활성화로 설정 - .refreshToken(member.getRefreshToken()) - .build(); - memberRepository.save(member); - } + memberRepository.updateStatus(Status.INACTIVE, memberId); ApiResponse apiResponse = ApiResponse.builder() .check(true) diff --git a/src/main/java/com/ttubeog/domain/member/domain/Member.java b/src/main/java/com/ttubeog/domain/member/domain/Member.java index 953d1c3b..3dece508 100644 --- a/src/main/java/com/ttubeog/domain/member/domain/Member.java +++ b/src/main/java/com/ttubeog/domain/member/domain/Member.java @@ -65,9 +65,4 @@ public boolean isRegisteredOAuthMember() { return nickname != null; } public boolean isNickNameChanged() { return nicknameChange; } - - public void updateName(String name) { - this.nickname = name; - } - } diff --git a/src/main/java/com/ttubeog/domain/member/domain/repository/MemberRepository.java b/src/main/java/com/ttubeog/domain/member/domain/repository/MemberRepository.java index 9992126d..38a82d5e 100644 --- a/src/main/java/com/ttubeog/domain/member/domain/repository/MemberRepository.java +++ b/src/main/java/com/ttubeog/domain/member/domain/repository/MemberRepository.java @@ -41,6 +41,9 @@ public interface MemberRepository extends JpaRepository{ @Query("update Member as m set m.nicknameChange = :nicknameChange where m.id = :memberId") void updateMemberNicknameChange(@Param("nicknameChange") Boolean nicknameChange, @Param("memberId") Long memberId); + @Modifying + @Query("update Member m set m.status = :status where m.id = :memberId") + void updateStatus(@Param("status") Status status, @Param("memberId") Long memberId); Boolean existsByNickname(String nickname); diff --git a/src/main/java/com/ttubeog/domain/member/presentation/MemberController.java b/src/main/java/com/ttubeog/domain/member/presentation/MemberController.java index b3e623bc..94616c94 100644 --- a/src/main/java/com/ttubeog/domain/member/presentation/MemberController.java +++ b/src/main/java/com/ttubeog/domain/member/presentation/MemberController.java @@ -94,30 +94,15 @@ public ResponseEntity logout( return memberService.deleteLogout(request); } -// @Operation(summary = "회원탈퇴", description = "현재 접속된 회원이 탈퇴 합니다.") -// @ApiResponses(value = { -// @ApiResponse(responseCode = "200", description = "회원탈퇴 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}), -// @ApiResponse(responseCode = "400", description = "회원탈퇴 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), -// }) -// @DeleteMapping("/delete") -// public ResponseEntity deleteUser( -// HttpServletRequest request -// ) { -// ResponseEntity responseEntity = memberService.deleteUser(request); -// -// if (responseEntity.getStatusCode().is2xxSuccessful()) { -// LocalDateTime localDateTime = LocalDateTime.now().plusDays(3); -// -// scheduledExecutorService.schedule(() -> { -// ResponseEntity deleteResponse = memberService.deleteInactiveMember(); -// -// if (deleteResponse.getStatusCode().is2xxSuccessful()) { -// System.out.println("회원 삭제 성공"); -// } else { -// System.out.println("회원 삭제 실패"); -// } -// }, 3, TimeUnit.DAYS); -// } -// return responseEntity; -// } + @Operation(summary = "회원탈퇴", description = "현재 접속된 회원이 탈퇴 합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "회원탈퇴 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}), + @ApiResponse(responseCode = "400", description = "회원탈퇴 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), + }) + @DeleteMapping("/delete") + public ResponseEntity deleteUser( + HttpServletRequest request + ) { + return memberService.deleteMember(request); + } }