From 05aef30e42a8ab576392cf10e37f920bb4977356 Mon Sep 17 00:00:00 2001 From: Hyesooo Date: Thu, 9 Nov 2023 01:42:54 +0900 Subject: [PATCH] =?UTF-8?q?:bug:[fix]:=20=ED=9A=8C=EC=9B=90=ED=83=88?= =?UTF-8?q?=ED=87=B4=20userID=20=EA=B8=B0=EB=B0=98=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pingpong/quoteBakery/sys/controller/UserController.java | 6 ++++-- .../com/pingpong/quoteBakery/sys/dto/WithdrawalDto.java | 2 +- .../quoteBakery/sys/resource/UserWithdrawalResource.java | 6 ++++-- .../com/pingpong/quoteBakery/sys/service/UserService.java | 5 +++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/pingpong/quoteBakery/sys/controller/UserController.java b/src/main/java/com/pingpong/quoteBakery/sys/controller/UserController.java index eb7b129..4dc76ba 100644 --- a/src/main/java/com/pingpong/quoteBakery/sys/controller/UserController.java +++ b/src/main/java/com/pingpong/quoteBakery/sys/controller/UserController.java @@ -73,12 +73,14 @@ public ApiRes searchUserByUid(@PathVariable("id") Long id) { /* * 회원 탈퇴 * */ - @PostMapping("/withdrawal") + @PostMapping("/withdrawal/{userId}") @Operation(summary = "회원 탈퇴", description = "회원 정보 삭제 및 탈퇴 사유를 저장한다.", responses = {@ApiResponse(responseCode = "200", description = "탈퇴 성공")} ) - public ApiRes signup(@RequestBody UserWithdrawalResource withdrawalResource) { + @Parameter(name = "userId", description = "userId", in = ParameterIn.PATH) + public ApiRes signup(@PathVariable("userId") Long userId, @RequestBody UserWithdrawalResource withdrawalResource) { + withdrawalResource.setUserId(userId); userService.withdrawalAccount(commonConverter.convertToGeneric(withdrawalResource, WithdrawalDto.class)); return ApiRes.createSuccessWithNoContent(); } diff --git a/src/main/java/com/pingpong/quoteBakery/sys/dto/WithdrawalDto.java b/src/main/java/com/pingpong/quoteBakery/sys/dto/WithdrawalDto.java index 4896680..052bb42 100644 --- a/src/main/java/com/pingpong/quoteBakery/sys/dto/WithdrawalDto.java +++ b/src/main/java/com/pingpong/quoteBakery/sys/dto/WithdrawalDto.java @@ -8,6 +8,6 @@ @Getter @Setter public class WithdrawalDto { - private String uid; + private Long userId; private String reason; } diff --git a/src/main/java/com/pingpong/quoteBakery/sys/resource/UserWithdrawalResource.java b/src/main/java/com/pingpong/quoteBakery/sys/resource/UserWithdrawalResource.java index 3b731da..7a4f31e 100644 --- a/src/main/java/com/pingpong/quoteBakery/sys/resource/UserWithdrawalResource.java +++ b/src/main/java/com/pingpong/quoteBakery/sys/resource/UserWithdrawalResource.java @@ -1,5 +1,6 @@ package com.pingpong.quoteBakery.sys.resource; +import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; @@ -9,8 +10,9 @@ @Getter @Setter public class UserWithdrawalResource { - @Schema(description = "탈퇴유저uid") - private String uid; + @Hidden + @Schema(description = "사용자ID") + private Long userId; @Schema(description = "탈퇴사유") private String reason; diff --git a/src/main/java/com/pingpong/quoteBakery/sys/service/UserService.java b/src/main/java/com/pingpong/quoteBakery/sys/service/UserService.java index 4a3e226..2ded430 100644 --- a/src/main/java/com/pingpong/quoteBakery/sys/service/UserService.java +++ b/src/main/java/com/pingpong/quoteBakery/sys/service/UserService.java @@ -87,12 +87,13 @@ public boolean validateUid(String uid){ @Transactional public void withdrawalAccount(WithdrawalDto dto){ + User user = userRepository.findById(dto.getUserId()).orElseThrow(() -> new BusinessInvalidValueException("해당 ID에 대한 사용자 정보가 없습니다.")); + String tokenUid = tokenService.getCurrentTokenInfo().getUid(); - String requestUid = dto.getUid(); + String requestUid = user.getUid(); if(!requestUid.equals(tokenUid)) throw new BusinessInvalidValueException("본인만 회원 탈퇴할 수 있습니다."); - User user = userRepository.findByUid(requestUid).orElseThrow(() -> new BusinessInvalidValueException("해당 ID에 대한 정보가 없습니다.")); userPreferenceRepository.deleteAllByUserId(user.getId()); likeRepository.deleteAllByUserId(user.getId()); userRepository.delete(user);