From 85e131e3244eabbbedde815975b00e2230bf662c Mon Sep 17 00:00:00 2001 From: minjun Date: Tue, 11 Jul 2023 22:22:42 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor]=20#302=20-=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20,=20=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20Builder=20=EC=82=AC=EC=9A=A9=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/cazait/domain/user/entity/User.java | 21 +++++++++++++++ .../domain/user/service/UserService.java | 26 +++++-------------- 2 files changed, 28 insertions(+), 19 deletions(-) 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 e1bb38cb..c24e2bca 100644 --- a/src/main/java/shop/cazait/domain/user/entity/User.java +++ b/src/main/java/shop/cazait/domain/user/entity/User.java @@ -7,6 +7,7 @@ import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; +import shop.cazait.domain.user.dto.UserUpdateInDTO; import shop.cazait.global.common.entity.BaseEntity; import shop.cazait.global.common.status.BaseStatus; @@ -47,5 +48,25 @@ public User(UUID id, String email, String password, String nickname, String refr this.refreshToken = refreshToken; // this.isKakao = KakaoIntegrated.NORMAL; } + + public static User loginUser(User user, String refreshToken){ + return User.builder() + .id(user.getId()) + .email(user.getEmail()) + .password(user.getPassword()) + .nickname(user.getNickname()) + .refreshToken(refreshToken) + .build(); + } + + public static User updateUserProfile(UUID userIdx, String refreshToken, UserUpdateInDTO userUpdateInDTO){ + return User.builder() + .id(userIdx) + .email(userUpdateInDTO.getEmail()) + .password(userUpdateInDTO.getPassword()) + .nickname(userUpdateInDTO.getNickname()) + .refreshToken(refreshToken) + .build(); + } } 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 ab43cf5c..0c5b08e3 100644 --- a/src/main/java/shop/cazait/domain/user/service/UserService.java +++ b/src/main/java/shop/cazait/domain/user/service/UserService.java @@ -81,13 +81,7 @@ public UserAuthenticateOutDTO logIn(UserAuthenticateInDTO userAuthenticateInDTO) String accessToken = jwtService.createJwt(userIdx); String refreshToken = jwtService.createRefreshToken(); - User loginUser = User.builder() - .id(findUser.getId()) - .email(findUser.getEmail()) - .password(findUser.getPassword()) - .nickname(findUser.getNickname()) - .refreshToken(refreshToken) - .build(); + User loginUser = User.loginUser(findUser,refreshToken); userRepository.save(loginUser); return UserAuthenticateOutDTO.of(findUser, accessToken, refreshToken, "user"); } @@ -109,19 +103,13 @@ public UserFindOutDTO getUserInfo(UUID userIdx) throws UserException { return UserFindOutDTO.of(findUser); } - public UserUpdateOutDTO modifyUser(UUID userIdx, UserUpdateInDTO userUpdateInDTO, String refreshToken) throws UserException { - User modifyUser = userUpdateInDTO.toEntity(); - userRepository.findById(userIdx).orElseThrow(()->new UserException(NOT_EXIST_USER)); + public UserUpdateOutDTO modifyUser(UUID userIdx, UserUpdateInDTO userUpdateInDTO) throws UserException { - User existUser = User.builder() - .id(userIdx) - .email(modifyUser.getEmail()) - .password(modifyUser.getPassword()) - .nickname(modifyUser.getNickname()) - .refreshToken(refreshToken) - .build(); - userRepository.save(existUser); - return UserUpdateOutDTO.of(existUser); + userRepository.findById(userIdx).orElseThrow(()->new UserException(NOT_EXIST_USER)); + String refreshToken = userRepository.findById(userIdx).get().getRefreshToken(); + User modifyUser = User.updateUserProfile(userIdx, refreshToken, userUpdateInDTO); + userRepository.save(modifyUser); + return UserUpdateOutDTO.of(modifyUser); } public UserDeleteOutDTO deleteUser(UUID userIdx) throws UserException {