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 3176e940..68c67455 100644 --- a/src/main/java/shop/cazait/domain/user/api/UserApiController.java +++ b/src/main/java/shop/cazait/domain/user/api/UserApiController.java @@ -15,11 +15,11 @@ import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.validation.Valid; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; + import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; + import shop.cazait.domain.user.dto.*; import shop.cazait.domain.user.exception.UserException; import shop.cazait.domain.user.service.UserService; @@ -40,25 +40,25 @@ public class UserApiController { @NoAuth @Operation(summary = "회원 가입", description = "User 정보를 추가하여 회원가입을 진행") @PostMapping("/sign-up") - public SuccessResponse createUser(@RequestBody @Valid PostUserReq postUserReq) + public SuccessResponse createUser(@RequestBody @Valid UserCreateInDTO userCreateInDTO) throws UserException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { - PostUserRes postUserRes = userService.createUser(postUserReq); - return new SuccessResponse<>(CREATE_USER, postUserRes); + UserCreateOutDTO userCreateOutDTO = userService.createUser(userCreateInDTO); + return new SuccessResponse<>(CREATE_USER, userCreateOutDTO); } @GetMapping("/all") @Operation(summary = "모든 회원을 조회", description = "회원가입된 모든 회원 정보를 조회") - public SuccessResponse> getUsers(){ - List allGetUserRes = userService.getAllUsers(); - return new SuccessResponse<>(SUCCESS, allGetUserRes); + public SuccessResponse> getUsers(){ + List allUserRes = userService.getAllUsers(); + return new SuccessResponse<>(SUCCESS, allUserRes); } @GetMapping("/{userId}") @Operation(summary = "특정 회원 정보를 조회", description ="자신의 계정 정보를 조회") @Parameter(name = "userIdx", description = "response로 발급 받은 계정 ID번호",example="1") - public SuccessResponse getUser( + public SuccessResponse getUser( @PathVariable(name = "userId") Long userIdx) throws UserException { - GetUserRes userInfoRes = userService.getUserInfo(userIdx); + UserFindOutDTO userInfoRes = userService.getUserInfo(userIdx); return new SuccessResponse<>(SUCCESS, userInfoRes); } @@ -68,38 +68,38 @@ public SuccessResponse getUser( @Parameter(name = "userIdx", description = "response로 발급 받은 계정 ID번호",example="1"), @Parameter(name = "REFRESH-TOKEN", description = "발급 받은 refreshtoken")} ) - public SuccessResponse modifyUser( + public SuccessResponse modifyUser( @PathVariable(name = "userId") Long userIdx, - @RequestBody @Valid PatchUserReq patchUserReq, + @RequestBody @Valid UserUpdateInDTO userUpdateInDTO, @RequestHeader(value="REFRESH-TOKEN") String refreshToken) throws UserException { //jwtService.isValidRefreshToken(refreshToken); - PatchUserRes patchUserRes = userService.modifyUser(userIdx, patchUserReq, refreshToken); - return new SuccessResponse<>(SUCCESS, patchUserRes); + UserUpdateOutDTO userUpdateOutDTO = userService.modifyUser(userIdx, userUpdateInDTO, refreshToken); + return new SuccessResponse<>(SUCCESS, userUpdateOutDTO); } @DeleteMapping("/{userId}") @Operation(summary = "특정한 회원 정보를 삭제", description = "자신의 계정 정보를 삭제") @Parameter(name = "userId", description = "response로 발급 받은 계정 ID번호",example="1") - public SuccessResponse deleteUser(@PathVariable(name = "userId") Long userIdx) throws UserException { - DeleteUserRes deleteUserRes = userService.deleteUser(userIdx); - return new SuccessResponse<>(SUCCESS, deleteUserRes); + public SuccessResponse deleteUser(@PathVariable(name = "userId") Long userIdx) throws UserException { + UserDeleteOutDTO userDeleteOutDTO = userService.deleteUser(userIdx); + return new SuccessResponse<>(SUCCESS, userDeleteOutDTO); } @NoAuth @PostMapping ("/email") @Operation(summary = "이메일 중복확인", description = "회원가입 전 이미 존재하는 이메일인지 중복확인") - public SuccessResponse checkDuplicateEmail(@RequestBody @Valid PostCheckDuplicateEmailReq postCheckDuplicateEmailReq) throws UserException { - SuccessResponse emailDuplicateSuccessResponse = userService.checkduplicateEmail(postCheckDuplicateEmailReq); + public SuccessResponse checkDuplicateEmail(@RequestBody @Valid UserFindDuplicateEmailInDTO userFindDuplicateEmailInDTO) throws UserException { + SuccessResponse emailDuplicateSuccessResponse = userService.checkduplicateEmail(userFindDuplicateEmailInDTO); return emailDuplicateSuccessResponse; } @NoAuth @PostMapping ("/nickname") @Operation(summary = "닉네임 중복확인", description = "회원가입 전 이미 존재하는 닉네임인지 중복확인") - public SuccessResponse checkDuplicateNickname(@RequestBody @Valid PostCheckDuplicateNicknameReq postCheckDuplicateNicknameReq) throws UserException { - SuccessResponse nicknameDuplicateSuccessResponse = userService.checkduplicateNickname(postCheckDuplicateNicknameReq); + public SuccessResponse checkDuplicateNickname(@RequestBody @Valid UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException { + SuccessResponse nicknameDuplicateSuccessResponse = userService.checkduplicateNickname(userFindDuplicateNicknameInDTO); return nicknameDuplicateSuccessResponse; } } diff --git a/src/main/java/shop/cazait/domain/user/dto/PostUserReq.java b/src/main/java/shop/cazait/domain/user/dto/UserCreateInDTO.java similarity index 92% rename from src/main/java/shop/cazait/domain/user/dto/PostUserReq.java rename to src/main/java/shop/cazait/domain/user/dto/UserCreateInDTO.java index 401d8f71..fa20d726 100644 --- a/src/main/java/shop/cazait/domain/user/dto/PostUserReq.java +++ b/src/main/java/shop/cazait/domain/user/dto/UserCreateInDTO.java @@ -11,7 +11,7 @@ @Schema(description = "유저 정보 Request : 회원 가입에 필요한 유저 정보") @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class PostUserReq { +public class UserCreateInDTO { @Email(message = "이메일 형식을 지키세요.") @NotBlank @@ -28,7 +28,7 @@ public class PostUserReq { private String nickname; @Builder - public PostUserReq(String email, String password, String nickname){ + public UserCreateInDTO(String email, String password, String nickname){ this.email = email; this.password = password; this.nickname = nickname; diff --git a/src/main/java/shop/cazait/domain/user/dto/PostUserRes.java b/src/main/java/shop/cazait/domain/user/dto/UserCreateOutDTO.java similarity index 100% rename from src/main/java/shop/cazait/domain/user/dto/PostUserRes.java rename to src/main/java/shop/cazait/domain/user/dto/UserCreateOutDTO.java diff --git a/src/main/java/shop/cazait/domain/user/dto/DeleteUserRes.java b/src/main/java/shop/cazait/domain/user/dto/UserDeleteOutDTO.java similarity index 87% rename from src/main/java/shop/cazait/domain/user/dto/DeleteUserRes.java rename to src/main/java/shop/cazait/domain/user/dto/UserDeleteOutDTO.java index edfe26d8..12d32a3c 100644 --- a/src/main/java/shop/cazait/domain/user/dto/DeleteUserRes.java +++ b/src/main/java/shop/cazait/domain/user/dto/UserDeleteOutDTO.java @@ -9,7 +9,7 @@ @Schema(description = "유저 삭제 Response : 삭제 완료된 유저 정보") @Getter @Builder(access = AccessLevel.PRIVATE) -public class DeleteUserRes { +public class UserDeleteOutDTO { @Schema(name = "회원 id", example = "1") private Long id; @@ -25,8 +25,8 @@ public class DeleteUserRes { - public static DeleteUserRes of(User user){ - return DeleteUserRes.builder() + public static UserDeleteOutDTO of(User user){ + return UserDeleteOutDTO.builder() .id(user.getId()) .email(user.getEmail()) .password(user.getPassword()) diff --git a/src/main/java/shop/cazait/domain/user/dto/PostCheckDuplicateEmailReq.java b/src/main/java/shop/cazait/domain/user/dto/UserFindDuplicateEmailInDTO.java similarity index 100% rename from src/main/java/shop/cazait/domain/user/dto/PostCheckDuplicateEmailReq.java rename to src/main/java/shop/cazait/domain/user/dto/UserFindDuplicateEmailInDTO.java diff --git a/src/main/java/shop/cazait/domain/user/dto/PostCheckDuplicateNicknameReq.java b/src/main/java/shop/cazait/domain/user/dto/UserFindDuplicateNicknameInDTO.java similarity index 100% rename from src/main/java/shop/cazait/domain/user/dto/PostCheckDuplicateNicknameReq.java rename to src/main/java/shop/cazait/domain/user/dto/UserFindDuplicateNicknameInDTO.java diff --git a/src/main/java/shop/cazait/domain/user/dto/GetUserRes.java b/src/main/java/shop/cazait/domain/user/dto/UserFindOutDTO.java similarity index 100% rename from src/main/java/shop/cazait/domain/user/dto/GetUserRes.java rename to src/main/java/shop/cazait/domain/user/dto/UserFindOutDTO.java diff --git a/src/main/java/shop/cazait/domain/user/dto/PatchUserReq.java b/src/main/java/shop/cazait/domain/user/dto/UserUpdateInDTO.java similarity index 100% rename from src/main/java/shop/cazait/domain/user/dto/PatchUserReq.java rename to src/main/java/shop/cazait/domain/user/dto/UserUpdateInDTO.java diff --git a/src/main/java/shop/cazait/domain/user/dto/PatchUserRes.java b/src/main/java/shop/cazait/domain/user/dto/UserUpdateOutDTO.java similarity index 100% rename from src/main/java/shop/cazait/domain/user/dto/PatchUserRes.java rename to src/main/java/shop/cazait/domain/user/dto/UserUpdateOutDTO.java 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 0bf3d39c..13dcedb7 100644 --- a/src/main/java/shop/cazait/domain/user/service/UserService.java +++ b/src/main/java/shop/cazait/domain/user/service/UserService.java @@ -42,25 +42,25 @@ public class UserService { private final UserRepository userRepository; private final JwtService jwtService; - public PostUserRes createUser(PostUserReq postUserReq) + public UserCreateOutDTO createUser(UserCreateInDTO userCreateInDTO) throws UserException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { - if (!userRepository.findByEmail(postUserReq.getEmail()).isEmpty()) { + if (!userRepository.findByEmail(userCreateInDTO.getEmail()).isEmpty()) { throw new UserException(EXIST_EMAIL); } - if (!userRepository.findByNickname(postUserReq.getNickname()).isEmpty()) { + if (!userRepository.findByNickname(userCreateInDTO.getNickname()).isEmpty()) { throw new UserException(EXIST_NICKNAME); } String pwd; - pwd = new AES128(Secret.USER_INFO_PASSWORD_KEY).encrypt(postUserReq.getPassword()); + pwd = new AES128(Secret.USER_INFO_PASSWORD_KEY).encrypt(userCreateInDTO.getPassword()); - PostUserReq EncryptPostUserReq = new PostUserReq(postUserReq.getEmail(), pwd, postUserReq.getNickname()); - User user = EncryptPostUserReq.toEntity(); + UserCreateInDTO encryptUserCreateInDTO = new UserCreateInDTO(userCreateInDTO.getEmail(), pwd, userCreateInDTO.getNickname()); + User user = encryptUserCreateInDTO.toEntity(); userRepository.save(user); - return PostUserRes.of(user); + return UserCreateOutDTO.of(user); } public UserAuthenticateOutDTO logIn(UserAuthenticateInDTO userAuthenticateInDTO) @@ -96,12 +96,12 @@ public UserAuthenticateOutDTO logIn(UserAuthenticateInDTO userAuthenticateInDTO) } @Transactional(readOnly = true) - public List getAllUsers() { + public List getAllUsers() { List allUsers = userRepository.findAll(); - List userListsRes = new ArrayList<>(); + List userListsRes = new ArrayList<>(); for (User user : allUsers) { - GetUserRes of = GetUserRes.of(user); + UserFindOutDTO of = UserFindOutDTO.of(user); userListsRes.add(of); } @@ -109,16 +109,16 @@ public List getAllUsers() { } @Transactional(readOnly = true) - public GetUserRes getUserInfo(Long userIdx) throws UserException { + public UserFindOutDTO getUserInfo(Long userIdx) throws UserException { if (userRepository.findById(userIdx).isEmpty()) { throw new UserException(NOT_EXIST_USER); } User findUser = userRepository.findById(userIdx).get(); - return GetUserRes.of(findUser); + return UserFindOutDTO.of(findUser); } - public PatchUserRes modifyUser(Long userIdx, PatchUserReq patchUserReq, String refreshToken) throws UserException { - User modifyUser = patchUserReq.toEntity(); + public UserUpdateOutDTO modifyUser(Long userIdx, UserUpdateInDTO userUpdateInDTO, String refreshToken) throws UserException { + User modifyUser = userUpdateInDTO.toEntity(); if (userRepository.findById(userIdx).isEmpty()) { throw new UserException(NOT_EXIST_USER); } @@ -132,29 +132,29 @@ public PatchUserRes modifyUser(Long userIdx, PatchUserReq patchUserReq, String r .refreshToken(refreshToken) .build(); userRepository.save(existUser); - return PatchUserRes.of(existUser); + return UserUpdateOutDTO.of(existUser); } - public DeleteUserRes deleteUser(Long userIdx) throws UserException { + public UserDeleteOutDTO deleteUser(Long userIdx) throws UserException { if (userRepository.findById(userIdx).isEmpty()) { throw new UserException(NOT_EXIST_USER); } User deleteUser = userRepository.findById(userIdx).get(); userRepository.delete(deleteUser); - return DeleteUserRes.of(deleteUser); + return UserDeleteOutDTO.of(deleteUser); } - public SuccessResponse checkduplicateEmail(PostCheckDuplicateEmailReq postCheckDuplicateEmailReq) throws UserException { - String email = postCheckDuplicateEmailReq.getEmail(); + public SuccessResponse checkduplicateEmail(UserFindDuplicateEmailInDTO userFindDuplicateEmailInDTO) throws UserException { + String email = userFindDuplicateEmailInDTO.getEmail(); if (!userRepository.findByEmail(email).isEmpty()) { throw new UserException(EXIST_EMAIL); } return new SuccessResponse(SIGNUP_AVAILABLE, email); } - public SuccessResponse checkduplicateNickname(PostCheckDuplicateNicknameReq postCheckDuplicateNicknameReq) throws UserException { - String nickname = postCheckDuplicateNicknameReq.getNickname(); + public SuccessResponse checkduplicateNickname(UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException { + String nickname = userFindDuplicateNicknameInDTO.getNickname(); if (!userRepository.findByNickname(nickname.trim()).isEmpty()) { throw new UserException(EXIST_NICKNAME); }