Skip to content

Commit

Permalink
[Chore] #283 - 메소드 네이밍 변경 (User)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjKim1229 committed Jun 21, 2023
1 parent a02faa4 commit e14f126
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 47 deletions.
42 changes: 21 additions & 21 deletions src/main/java/shop/cazait/domain/user/api/UserApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,25 +40,25 @@ public class UserApiController {
@NoAuth
@Operation(summary = "회원 가입", description = "User 정보를 추가하여 회원가입을 진행")
@PostMapping("/sign-up")
public SuccessResponse<PostUserRes> createUser(@RequestBody @Valid PostUserReq postUserReq)
public SuccessResponse<UserCreateOutDTO> 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<List<GetUserRes>> getUsers(){
List<GetUserRes> allGetUserRes = userService.getAllUsers();
return new SuccessResponse<>(SUCCESS, allGetUserRes);
public SuccessResponse<List<UserFindOutDTO>> getUsers(){
List<UserFindOutDTO> allUserRes = userService.getAllUsers();
return new SuccessResponse<>(SUCCESS, allUserRes);
}

@GetMapping("/{userId}")
@Operation(summary = "특정 회원 정보를 조회", description ="자신의 계정 정보를 조회")
@Parameter(name = "userIdx", description = "response로 발급 받은 계정 ID번호",example="1")
public SuccessResponse<GetUserRes> getUser(
public SuccessResponse<UserFindOutDTO> getUser(
@PathVariable(name = "userId") Long userIdx) throws UserException {
GetUserRes userInfoRes = userService.getUserInfo(userIdx);
UserFindOutDTO userInfoRes = userService.getUserInfo(userIdx);
return new SuccessResponse<>(SUCCESS, userInfoRes);
}

Expand All @@ -68,38 +68,38 @@ public SuccessResponse<GetUserRes> getUser(
@Parameter(name = "userIdx", description = "response로 발급 받은 계정 ID번호",example="1"),
@Parameter(name = "REFRESH-TOKEN", description = "발급 받은 refreshtoken")}
)
public SuccessResponse<PatchUserRes> modifyUser(
public SuccessResponse<UserUpdateOutDTO> 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<DeleteUserRes> deleteUser(@PathVariable(name = "userId") Long userIdx) throws UserException {
DeleteUserRes deleteUserRes = userService.deleteUser(userIdx);
return new SuccessResponse<>(SUCCESS, deleteUserRes);
public SuccessResponse<UserDeleteOutDTO> 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<String> checkDuplicateEmail(@RequestBody @Valid PostCheckDuplicateEmailReq postCheckDuplicateEmailReq) throws UserException {
SuccessResponse<String> emailDuplicateSuccessResponse = userService.checkduplicateEmail(postCheckDuplicateEmailReq);
public SuccessResponse<String> checkDuplicateEmail(@RequestBody @Valid UserFindDuplicateEmailInDTO userFindDuplicateEmailInDTO) throws UserException {
SuccessResponse<String> emailDuplicateSuccessResponse = userService.checkduplicateEmail(userFindDuplicateEmailInDTO);
return emailDuplicateSuccessResponse;
}

@NoAuth
@PostMapping ("/nickname")
@Operation(summary = "닉네임 중복확인", description = "회원가입 전 이미 존재하는 닉네임인지 중복확인")
public SuccessResponse<String> checkDuplicateNickname(@RequestBody @Valid PostCheckDuplicateNicknameReq postCheckDuplicateNicknameReq) throws UserException {
SuccessResponse<String> nicknameDuplicateSuccessResponse = userService.checkduplicateNickname(postCheckDuplicateNicknameReq);
public SuccessResponse<String> checkDuplicateNickname(@RequestBody @Valid UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException {
SuccessResponse<String> nicknameDuplicateSuccessResponse = userService.checkduplicateNickname(userFindDuplicateNicknameInDTO);
return nicknameDuplicateSuccessResponse;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Schema(description = "유저 정보 Request : 회원 가입에 필요한 유저 정보")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PostUserReq {
public class UserCreateInDTO {

@Email(message = "이메일 형식을 지키세요.")
@NotBlank
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/shop/cazait/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -96,29 +96,29 @@ public UserAuthenticateOutDTO logIn(UserAuthenticateInDTO userAuthenticateInDTO)
}

@Transactional(readOnly = true)
public List<GetUserRes> getAllUsers() {
public List<UserFindOutDTO> getAllUsers() {
List<User> allUsers = userRepository.findAll();
List<GetUserRes> userListsRes = new ArrayList<>();
List<UserFindOutDTO> userListsRes = new ArrayList<>();

for (User user : allUsers) {
GetUserRes of = GetUserRes.of(user);
UserFindOutDTO of = UserFindOutDTO.of(user);
userListsRes.add(of);
}

return userListsRes;
}

@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);
}
Expand All @@ -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<String> checkduplicateEmail(PostCheckDuplicateEmailReq postCheckDuplicateEmailReq) throws UserException {
String email = postCheckDuplicateEmailReq.getEmail();
public SuccessResponse<String> 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<String> checkduplicateNickname(PostCheckDuplicateNicknameReq postCheckDuplicateNicknameReq) throws UserException {
String nickname = postCheckDuplicateNicknameReq.getNickname();
public SuccessResponse<String> checkduplicateNickname(UserFindDuplicateNicknameInDTO userFindDuplicateNicknameInDTO) throws UserException {
String nickname = userFindDuplicateNicknameInDTO.getNickname();
if (!userRepository.findByNickname(nickname.trim()).isEmpty()) {
throw new UserException(EXIST_NICKNAME);
}
Expand Down

0 comments on commit e14f126

Please sign in to comment.