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