Skip to content

Commit

Permalink
[Chore] #283 - 메소드 네이빙 변경 (User)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjKim1229 committed Jul 28, 2023
1 parent 78fb519 commit 2c5eaf1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/shop/cazait/domain/user/api/UserApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,51 +47,51 @@ public SuccessResponse<UserCreateOutDTO> createUser(@RequestBody @Valid UserCrea
@GetMapping("/all")
@Operation(summary = "모든 회원을 조회", description = "회원가입된 모든 회원 정보를 조회")
public SuccessResponse<List<UserFindOutDTO>> getUsers(){
List<UserFindOutDTO> allUserRes = userService.getAllUsers();
List<UserFindOutDTO> allUserRes = userService.getUsers();
return new SuccessResponse<>(SUCCESS, allUserRes);
}

@GetMapping("/{userId}")
@Operation(summary = "특정 회원 정보를 조회", description ="자신의 계정 정보를 조회")
@Parameter(name = "userId", description = "response로 발급 받은 계정 ID번호")
public SuccessResponse<UserFindOutDTO> 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<UserUpdateOutDTO> modifyUser(
public SuccessResponse<UserUpdateOutDTO> 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);

}

@DeleteMapping("/{userId}")
@Operation(summary = "특정한 회원 정보를 삭제", description = "자신의 계정 정보를 삭제")
@Parameter(name = "userId", description = "response로 발급 받은 계정 ID번호")
public SuccessResponse<UserDeleteOutDTO> deleteUser(@PathVariable(name = "userId") UUID userIdx) throws UserException {
UserDeleteOutDTO userDeleteOutDTO = userService.deleteUser(userIdx);
public SuccessResponse<UserDeleteOutDTO> 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<String> checkDuplicateaccountNumber(@RequestBody @Valid UserFindDuplicateAccountNumberInDTO userFindDuplicateEmailInDTO) throws UserException {
SuccessResponse<String> accountNumberSuccessResponse = userService.checkduplicateaccountNumber(userFindDuplicateEmailInDTO);
public SuccessResponse<String> findUserDuplicateAccountName(@RequestBody @Valid UserFindDuplicateAccountNumberInDTO userFindDuplicateEmailInDTO) throws UserException {
SuccessResponse<String> accountNumberSuccessResponse = userService.findUserDuplicateAccountName(userFindDuplicateEmailInDTO);
return accountNumberSuccessResponse;
}

@NoAuth
@PostMapping ("/duplicate-check/nickname")
@Operation(summary = "닉네임 중복확인", description = "회원가입 전 이미 존재하는 닉네임인지 중복확인")
public SuccessResponse<String> checkDuplicateNickname(@RequestBody @Valid UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException {
SuccessResponse<String> nicknameDuplicateSuccessResponse = userService.checkduplicateNickname(userFindDuplicateNicknameInDTO);
public SuccessResponse<String> findUserDuplicateNickname(@RequestBody @Valid UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException {
SuccessResponse<String> nicknameDuplicateSuccessResponse = userService.findUserDuplicateNickname(userFindDuplicateNicknameInDTO);
return nicknameDuplicateSuccessResponse;
}

Expand All @@ -106,16 +106,16 @@ public SuccessResponse<UserFindAccountNameOutDTO> findUserAccountName(@RequestBo
@NoAuth
@PostMapping("/reset-password/accountname")
@Operation(summary = "비밀번호 변경 (아이디 입력)", description = "비밀번호 변경시 가입한 아이디 입력")
public SuccessResponse<UserEnterAccountNameInResetPasswordOutDTO> verifyUserInResetPassword(@RequestBody UserEnterAccountNameInResetPasswordOutDTO userEnterAccountNameInResetPasswordOutDTO) throws UserException {
UserEnterAccountNameInResetPasswordOutDTO userEnterAccountNameInResetPasswordOUTDTO = userService.verifyUserInResetPassword(userEnterAccountNameInResetPasswordOutDTO.getAccountName());
public SuccessResponse<UserEnterAccountNameInResetPasswordOutDTO> 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<UserEnterPasswordInResetPasswordOutDTO> updateUserPassword(@RequestBody UserEnterPasswordInResetPasswordInDTO userEnterPasswordInResetPasswordInDTO) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, UserException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
UserEnterPasswordInResetPasswordOutDTO userEnterPasswordInResetPasswordOutDTO = userService.updateUserPassword(userEnterPasswordInResetPasswordInDTO.getUserPhoneNumber(), userEnterPasswordInResetPasswordInDTO.getPassword());
public SuccessResponse<UserEnterPasswordInResetPasswordOutDTO> 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);
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/shop/cazait/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/shop/cazait/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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())
Expand All @@ -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();
Expand All @@ -92,27 +92,27 @@ public UserAuthenticateOutDTO logIn(UserAuthenticateInDTO userAuthenticateInDTO)
}

@Transactional(readOnly = true)
public List<UserFindOutDTO> getAllUsers() {
public List<UserFindOutDTO> getUsers() {
List<User> allUsers = userRepository.findAll();
return allUsers.stream()
.map(UserFindOutDTO::of)
.toList();
}

@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);

//유저 정보 수정
Expand All @@ -121,27 +121,27 @@ 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();
userRepository.delete(deleteUser);
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<String> checkduplicateaccountNumber(UserFindDuplicateAccountNumberInDTO userFindDuplicateAccountNumberInDTO) throws UserException {
public SuccessResponse<String> findUserDuplicateAccountName(UserFindDuplicateAccountNumberInDTO userFindDuplicateAccountNumberInDTO) throws UserException {
String accountNumber = userFindDuplicateAccountNumberInDTO.getAccountNumber();
if (userRepository.findByAccountNumber(accountNumber).isPresent()) {
throw new UserException(EXIST_ACCOUNTNUMBER);
}
return new SuccessResponse<>(SIGNUP_AVAILABLE, accountNumber);
}

public SuccessResponse<String> checkduplicateNickname(UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException {
public SuccessResponse<String> findUserDuplicateNickname(UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException {
String nickname = userFindDuplicateNicknameInDTO.getNickname();
if (userRepository.findByNickname(nickname.trim()).isPresent()) {
throw new UserException(EXIST_NICKNAME);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2c5eaf1

Please sign in to comment.