From 824c41b3f7a1b65c4a620b12c268ceed86ccf332 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Wed, 30 Oct 2024 10:11:37 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20id=20=EC=A0=95=EB=B3=B4=20=EA=B0=80=EC=A0=B8?= =?UTF-8?q?=EC=98=A4=EB=8A=94=20=EC=95=A0=EB=85=B8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=A0=81=EC=9A=A9=20(#41)=20(KAN-96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserApi.java | 6 +++--- .../user/controller/UserController.java | 14 ++++++-------- .../user/service/UserService.java | 6 +----- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/user/controller/UserApi.java b/src/main/java/org/ioteatime/meonghanyangserver/user/controller/UserApi.java index 53be25a9..4dc43ddb 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/user/controller/UserApi.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/user/controller/UserApi.java @@ -4,9 +4,9 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.ioteatime.meonghanyangserver.common.api.Api; +import org.ioteatime.meonghanyangserver.common.utils.LoginMember; import org.ioteatime.meonghanyangserver.user.dto.request.ChangePasswordRequest; import org.ioteatime.meonghanyangserver.user.dto.response.UserDetailResponse; -import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -17,9 +17,9 @@ public interface UserApi { Api getUserDetail(@PathVariable("userId") Long userId); @Operation(summary = "회원 정보를 삭제합니다.") - Api deleteUser(@PathVariable("userId") Long userId); + Api deleteUser(@LoginMember Long userId); @Operation(summary = "회원의 비밀번호를 변경합니다.") Api changeUserPassword( - Authentication authentication, @RequestBody @Valid ChangePasswordRequest request); + @LoginMember Long userId, @RequestBody @Valid ChangePasswordRequest request); } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/user/controller/UserController.java b/src/main/java/org/ioteatime/meonghanyangserver/user/controller/UserController.java index 6331d7ca..fb0f438f 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/user/controller/UserController.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/user/controller/UserController.java @@ -3,10 +3,10 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.ioteatime.meonghanyangserver.common.api.Api; +import org.ioteatime.meonghanyangserver.common.utils.LoginMember; import org.ioteatime.meonghanyangserver.user.dto.request.ChangePasswordRequest; import org.ioteatime.meonghanyangserver.user.dto.response.UserDetailResponse; import org.ioteatime.meonghanyangserver.user.service.UserService; -import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; @RestController @@ -16,23 +16,21 @@ public class UserController implements UserApi { private final UserService userService; @GetMapping("/{userId}") - public Api getUserDetail(Long userId) { + public Api getUserDetail(@PathVariable("userId") Long userId) { UserDetailResponse userDto = userService.getUserDetail(userId); return Api.OK(userDto); } - @DeleteMapping("/{userId}") - public Api deleteUser(Long userId) { + @DeleteMapping + public Api deleteUser(@LoginMember Long userId) { userService.deleteUser(userId); return Api.OK(); } @PutMapping("/password") public Api changeUserPassword( - Authentication authentication, @RequestBody @Valid ChangePasswordRequest request) { - - userService.changeUserPassword(authentication, request); - + @LoginMember Long userId, @RequestBody @Valid ChangePasswordRequest request) { + userService.changeUserPassword(userId, request); return Api.OK(); } } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/user/service/UserService.java b/src/main/java/org/ioteatime/meonghanyangserver/user/service/UserService.java index 59e5a94a..ea0aed1f 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/user/service/UserService.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/user/service/UserService.java @@ -4,11 +4,9 @@ import org.ioteatime.meonghanyangserver.common.error.ErrorTypeCode; import org.ioteatime.meonghanyangserver.common.exception.ApiException; import org.ioteatime.meonghanyangserver.user.domain.UserEntity; -import org.ioteatime.meonghanyangserver.user.dto.CustomUserDetail; import org.ioteatime.meonghanyangserver.user.dto.request.ChangePasswordRequest; import org.ioteatime.meonghanyangserver.user.dto.response.UserDetailResponse; import org.ioteatime.meonghanyangserver.user.repository.UserRepository; -import org.springframework.security.core.Authentication; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -34,11 +32,9 @@ public void deleteUser(Long userId) { } @Transactional - public void changeUserPassword(Authentication authentication, ChangePasswordRequest request) { + public void changeUserPassword(Long userId, ChangePasswordRequest request) { String currentPassword = request.getCurrentPassword(); String newPassword = request.getNewPassword(); - CustomUserDetail userDetails = (CustomUserDetail) authentication.getPrincipal(); - Long userId = userDetails.getUserEntity().getId(); UserEntity userEntity = userRepository