Skip to content

Commit

Permalink
[Refactor] #302 - 로그인 , 유저 정보 수정 Builder 사용 함수 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
mjKim1229 committed Jul 11, 2023
1 parent 9471d29 commit 85e131e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
21 changes: 21 additions & 0 deletions src/main/java/shop/cazait/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}

26 changes: 7 additions & 19 deletions src/main/java/shop/cazait/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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 {
Expand Down

0 comments on commit 85e131e

Please sign in to comment.