From 2c5eaf123e1341f9accac0b1ac0e950e0de9dca1 Mon Sep 17 00:00:00 2001 From: minjun Date: Sat, 29 Jul 2023 08:50:27 +0900 Subject: [PATCH] =?UTF-8?q?[Chore]=20#283=20-=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EB=84=A4=EC=9D=B4=EB=B9=99=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?(User)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/service/AuthService.java | 2 +- .../domain/auth/service/KakaoService.java | 2 +- .../domain/user/api/UserApiController.java | 28 ++++++++-------- .../shop/cazait/domain/user/entity/User.java | 8 +---- .../domain/user/service/UserService.java | 32 +++++++++---------- 5 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/main/java/shop/cazait/domain/auth/service/AuthService.java b/src/main/java/shop/cazait/domain/auth/service/AuthService.java index 6ee25250..23197e71 100644 --- a/src/main/java/shop/cazait/domain/auth/service/AuthService.java +++ b/src/main/java/shop/cazait/domain/auth/service/AuthService.java @@ -78,7 +78,7 @@ public UserAuthenticateOutDTO reIssueTokensByRole(Role exactRole, String accessT public UserAuthenticateOutDTO logInByRole(Role exactRole, UserAuthenticateInDTO userAuthenticateInDTO) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, UserException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException, MasterException { if (exactRole.equals(USER)) { - return userService.logIn(userAuthenticateInDTO); + return userService.logInUser(userAuthenticateInDTO); } else { return masterService.LoginMaster(userAuthenticateInDTO); } diff --git a/src/main/java/shop/cazait/domain/auth/service/KakaoService.java b/src/main/java/shop/cazait/domain/auth/service/KakaoService.java index 1fc4c0c0..cddd5e7f 100644 --- a/src/main/java/shop/cazait/domain/auth/service/KakaoService.java +++ b/src/main/java/shop/cazait/domain/auth/service/KakaoService.java @@ -75,7 +75,7 @@ public UserAuthenticateOutDTO kakaoLoginUser(Long kakaoId){ String accessToken = jwtService.createJwt(id); String refreshToken = jwtService.createRefreshToken(); - User kakaoLoginUser = user.kakaoLoginUser(refreshToken); + User kakaoLoginUser = user.updateUserRefreshToken(refreshToken); userRepository.save(kakaoLoginUser); return UserAuthenticateOutDTO.of(user, accessToken); diff --git a/src/main/java/shop/cazait/domain/user/api/UserApiController.java b/src/main/java/shop/cazait/domain/user/api/UserApiController.java index bedfc4f9..c234854c 100644 --- a/src/main/java/shop/cazait/domain/user/api/UserApiController.java +++ b/src/main/java/shop/cazait/domain/user/api/UserApiController.java @@ -47,7 +47,7 @@ public SuccessResponse createUser(@RequestBody @Valid UserCrea @GetMapping("/all") @Operation(summary = "모든 회원을 조회", description = "회원가입된 모든 회원 정보를 조회") public SuccessResponse> getUsers(){ - List allUserRes = userService.getAllUsers(); + List allUserRes = userService.getUsers(); return new SuccessResponse<>(SUCCESS, allUserRes); } @@ -55,18 +55,18 @@ public SuccessResponse> getUsers(){ @Operation(summary = "특정 회원 정보를 조회", description ="자신의 계정 정보를 조회") @Parameter(name = "userId", description = "response로 발급 받은 계정 ID번호") public SuccessResponse getUser(@PathVariable(name = "userId") UUID userIdx) throws UserException { - UserFindOutDTO userInfoRes = userService.getUserInfo(userIdx); + UserFindOutDTO userInfoRes = userService.getUser(userIdx); return new SuccessResponse<>(SUCCESS, userInfoRes); } @PatchMapping("/{userId}") @Operation(summary="특정한 회원 정보를 수정", description = "자신의 계정 정보를 수정") @Parameter(name = "userId", description = "response로 발급 받은 계정 ID번호") - public SuccessResponse modifyUser( + public SuccessResponse updateUserProfile( @PathVariable(name = "userId") UUID userIdx, @RequestBody @Valid UserUpdateInDTO userUpdateInDTO) throws UserException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { - UserUpdateOutDTO userUpdateOutDTO = userService.modifyUser(userIdx, userUpdateInDTO); + UserUpdateOutDTO userUpdateOutDTO = userService.updateUserProfile(userIdx, userUpdateInDTO); return new SuccessResponse<>(SUCCESS, userUpdateOutDTO); } @@ -74,24 +74,24 @@ public SuccessResponse modifyUser( @DeleteMapping("/{userId}") @Operation(summary = "특정한 회원 정보를 삭제", description = "자신의 계정 정보를 삭제") @Parameter(name = "userId", description = "response로 발급 받은 계정 ID번호") - public SuccessResponse deleteUser(@PathVariable(name = "userId") UUID userIdx) throws UserException { - UserDeleteOutDTO userDeleteOutDTO = userService.deleteUser(userIdx); + public SuccessResponse deleteUserById(@PathVariable(name = "userId") UUID userIdx) throws UserException { + UserDeleteOutDTO userDeleteOutDTO = userService.deleteUserById(userIdx); return new SuccessResponse<>(SUCCESS, userDeleteOutDTO); } @NoAuth @PostMapping ("/duplicate-check/accountname") @Operation(summary = "아이디 중복확인", description = "회원가입 전 이미 존재하는 아이디인지 중복확인") - public SuccessResponse checkDuplicateaccountNumber(@RequestBody @Valid UserFindDuplicateAccountNumberInDTO userFindDuplicateEmailInDTO) throws UserException { - SuccessResponse accountNumberSuccessResponse = userService.checkduplicateaccountNumber(userFindDuplicateEmailInDTO); + public SuccessResponse findUserDuplicateAccountName(@RequestBody @Valid UserFindDuplicateAccountNumberInDTO userFindDuplicateEmailInDTO) throws UserException { + SuccessResponse accountNumberSuccessResponse = userService.findUserDuplicateAccountName(userFindDuplicateEmailInDTO); return accountNumberSuccessResponse; } @NoAuth @PostMapping ("/duplicate-check/nickname") @Operation(summary = "닉네임 중복확인", description = "회원가입 전 이미 존재하는 닉네임인지 중복확인") - public SuccessResponse checkDuplicateNickname(@RequestBody @Valid UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException { - SuccessResponse nicknameDuplicateSuccessResponse = userService.checkduplicateNickname(userFindDuplicateNicknameInDTO); + public SuccessResponse findUserDuplicateNickname(@RequestBody @Valid UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException { + SuccessResponse nicknameDuplicateSuccessResponse = userService.findUserDuplicateNickname(userFindDuplicateNicknameInDTO); return nicknameDuplicateSuccessResponse; } @@ -106,16 +106,16 @@ public SuccessResponse findUserAccountName(@RequestBo @NoAuth @PostMapping("/reset-password/accountname") @Operation(summary = "비밀번호 변경 (아이디 입력)", description = "비밀번호 변경시 가입한 아이디 입력") - public SuccessResponse verifyUserInResetPassword(@RequestBody UserEnterAccountNameInResetPasswordOutDTO userEnterAccountNameInResetPasswordOutDTO) throws UserException { - UserEnterAccountNameInResetPasswordOutDTO userEnterAccountNameInResetPasswordOUTDTO = userService.verifyUserInResetPassword(userEnterAccountNameInResetPasswordOutDTO.getAccountName()); + public SuccessResponse verifyUserAccountNameInResetPassword(@RequestBody UserEnterAccountNameInResetPasswordOutDTO userEnterAccountNameInResetPasswordOutDTO) throws UserException { + UserEnterAccountNameInResetPasswordOutDTO userEnterAccountNameInResetPasswordOUTDTO = userService.verifyUserAccountNameInResetPassword(userEnterAccountNameInResetPasswordOutDTO.getAccountName()); return new SuccessResponse<>(SUCCESS, userEnterAccountNameInResetPasswordOUTDTO); } @NoAuth @PatchMapping("/reset-password/password") @Operation(summary = "비밀번호 변경 (새 비밀번호 입력)", description = "변경하려는 새로운 비밀번호를 입력") - public SuccessResponse updateUserPassword(@RequestBody UserEnterPasswordInResetPasswordInDTO userEnterPasswordInResetPasswordInDTO) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, UserException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { - UserEnterPasswordInResetPasswordOutDTO userEnterPasswordInResetPasswordOutDTO = userService.updateUserPassword(userEnterPasswordInResetPasswordInDTO.getUserPhoneNumber(), userEnterPasswordInResetPasswordInDTO.getPassword()); + public SuccessResponse updateUserPasswordInResetPassword(@RequestBody UserEnterPasswordInResetPasswordInDTO userEnterPasswordInResetPasswordInDTO) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, UserException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + UserEnterPasswordInResetPasswordOutDTO userEnterPasswordInResetPasswordOutDTO = userService.updateUserPasswordInResetPassword(userEnterPasswordInResetPasswordInDTO.getUserPhoneNumber(), userEnterPasswordInResetPasswordInDTO.getPassword()); return new SuccessResponse<>(SUCCESS, userEnterPasswordInResetPasswordOutDTO); } } diff --git a/src/main/java/shop/cazait/domain/user/entity/User.java b/src/main/java/shop/cazait/domain/user/entity/User.java index eb182a3c..8a5560cf 100644 --- a/src/main/java/shop/cazait/domain/user/entity/User.java +++ b/src/main/java/shop/cazait/domain/user/entity/User.java @@ -78,13 +78,7 @@ public static User kakaoSignUpUser(Long kakaoId){ .build(); } - public User kakaoLoginUser(String refreshToken) { - this.refreshToken = refreshToken; - - return this; - } - - public User updateUserPassword(String password){ + public User updateUserPasswordInResetPassword(String password){ this.password = password; return this; diff --git a/src/main/java/shop/cazait/domain/user/service/UserService.java b/src/main/java/shop/cazait/domain/user/service/UserService.java index f09c1d04..9080c98c 100644 --- a/src/main/java/shop/cazait/domain/user/service/UserService.java +++ b/src/main/java/shop/cazait/domain/user/service/UserService.java @@ -55,7 +55,7 @@ public UserCreateOutDTO createUser(UserCreateInDTO userCreateInDTO) throw new UserException(EXIST_NICKNAME); } - String encryptedPassword = encryptPassword(userCreateInDTO.getPassword()); + String encryptedPassword = encryptUserPassword(userCreateInDTO.getPassword()); UserCreateInDTO encryptUserCreateInDTO = userCreateInDTO.encryptUserUpdateDTO(userCreateInDTO, encryptedPassword); User user = UserCreateInDTO.toEntity(encryptUserCreateInDTO); @@ -64,7 +64,7 @@ public UserCreateOutDTO createUser(UserCreateInDTO userCreateInDTO) return UserCreateOutDTO.of(user); } - public UserAuthenticateOutDTO logIn(UserAuthenticateInDTO userAuthenticateInDTO) + public UserAuthenticateOutDTO logInUser(UserAuthenticateInDTO userAuthenticateInDTO) throws UserException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { User findUser = userRepository.findByAccountNumber(userAuthenticateInDTO.getAccountNumber()) @@ -73,7 +73,7 @@ public UserAuthenticateOutDTO logIn(UserAuthenticateInDTO userAuthenticateInDTO) //DB에 있는 암호화된 비밀번호 String findUserPassword = findUser.getPassword(); //로그인 시 입력한 비밀번호를 암호화 - String loginPassword = encryptPassword(userAuthenticateInDTO.getPassword()); + String loginPassword = encryptUserPassword(userAuthenticateInDTO.getPassword()); if (findUserPassword.equals(loginPassword)) { UUID userIdx = findUser.getId(); @@ -92,7 +92,7 @@ public UserAuthenticateOutDTO logIn(UserAuthenticateInDTO userAuthenticateInDTO) } @Transactional(readOnly = true) - public List getAllUsers() { + public List getUsers() { List allUsers = userRepository.findAll(); return allUsers.stream() .map(UserFindOutDTO::of) @@ -100,19 +100,19 @@ public List getAllUsers() { } @Transactional(readOnly = true) - public UserFindOutDTO getUserInfo(UUID userIdx) throws UserException { + public UserFindOutDTO getUser(UUID userIdx) throws UserException { userRepository.findById(userIdx).orElseThrow(() -> new UserException(NOT_EXIST_USER)); User findUser = userRepository.findById(userIdx).get(); return UserFindOutDTO.of(findUser); } - public UserUpdateOutDTO modifyUser(UUID userIdx, UserUpdateInDTO userUpdateInDTO) throws UserException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + public UserUpdateOutDTO updateUserProfile(UUID userIdx, UserUpdateInDTO userUpdateInDTO) throws UserException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { User existUser = userRepository.findById(userIdx) .orElseThrow(() -> new UserException(NOT_EXIST_USER)); //DTO의 비밀번호 암호화 - String encryptedPassword = encryptPassword(userUpdateInDTO.getPassword()); + String encryptedPassword = encryptUserPassword(userUpdateInDTO.getPassword()); UserUpdateInDTO encryptedUserUpdateDTO = userUpdateInDTO.encryptUserUpdateDTO(encryptedPassword); //유저 정보 수정 @@ -121,7 +121,7 @@ public UserUpdateOutDTO modifyUser(UUID userIdx, UserUpdateInDTO userUpdateInDTO return UserUpdateOutDTO.of(modifiedUser); } - public UserDeleteOutDTO deleteUser(UUID userIdx) throws UserException { + public UserDeleteOutDTO deleteUserById(UUID userIdx) throws UserException { userRepository.findById(userIdx).orElseThrow(() -> new UserException(NOT_EXIST_USER)); User deleteUser = userRepository.findById(userIdx).get(); @@ -129,11 +129,11 @@ public UserDeleteOutDTO deleteUser(UUID userIdx) throws UserException { return UserDeleteOutDTO.of(deleteUser); } - public String encryptPassword(String password) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + public String encryptUserPassword(String password) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { return new AES128(PASSWORD_SECRET_KEY).encrypt(password); } - public SuccessResponse checkduplicateaccountNumber(UserFindDuplicateAccountNumberInDTO userFindDuplicateAccountNumberInDTO) throws UserException { + public SuccessResponse findUserDuplicateAccountName(UserFindDuplicateAccountNumberInDTO userFindDuplicateAccountNumberInDTO) throws UserException { String accountNumber = userFindDuplicateAccountNumberInDTO.getAccountNumber(); if (userRepository.findByAccountNumber(accountNumber).isPresent()) { throw new UserException(EXIST_ACCOUNTNUMBER); @@ -141,7 +141,7 @@ public SuccessResponse checkduplicateaccountNumber(UserFindDuplicateAcco return new SuccessResponse<>(SIGNUP_AVAILABLE, accountNumber); } - public SuccessResponse checkduplicateNickname(UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException { + public SuccessResponse findUserDuplicateNickname(UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException { String nickname = userFindDuplicateNicknameInDTO.getNickname(); if (userRepository.findByNickname(nickname.trim()).isPresent()) { throw new UserException(EXIST_NICKNAME); @@ -212,24 +212,24 @@ public UserFindAccountNameOutDTO findUserAccountName(String phoneNumber) throws return UserFindAccountNameOutDTO.of(user); } - public UserEnterAccountNameInResetPasswordOutDTO verifyUserInResetPassword(String accountName) throws UserException { + public UserEnterAccountNameInResetPasswordOutDTO verifyUserAccountNameInResetPassword(String accountName) throws UserException { User user = userRepository.findByAccountNumber(accountName) .orElseThrow(() -> new UserException(NOT_EXIST_USER)); return UserEnterAccountNameInResetPasswordOutDTO.of(user); } - public UserEnterPasswordInResetPasswordOutDTO updateUserPassword(String phoneNumber, String password) throws UserException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + public UserEnterPasswordInResetPasswordOutDTO updateUserPasswordInResetPassword(String phoneNumber, String password) throws UserException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { User user = userRepository.findByPhoneNumber(phoneNumber) .orElseThrow(() -> new UserException(NOT_EXIST_USER)); - String encryptPassword = encryptPassword(password); - if(user.getPassword().equals(encryptPassword)){ + String encryptUserPassword = encryptUserPassword(password); + if(user.getPassword().equals(encryptUserPassword)){ throw new UserException(SAME_AS_CURRENT_PASSWORD); } //비밀번호 암호화 - User updatePasswordUser = user.updateUserPassword(encryptPassword); + User updatePasswordUser = user.updateUserPasswordInResetPassword(encryptUserPassword); userRepository.save(updatePasswordUser); return UserEnterPasswordInResetPasswordOutDTO.of(user,password);