Skip to content

Commit

Permalink
[#16] refactor: Duplicated 메소드 분리 (username, email)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyoungchoi95 committed Aug 20, 2021
1 parent 9bb2f86 commit 061f34e
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public UserService(UserRepository userRepository, PasswordEncoder passwordEncode

@Transactional
public User join(@Valid User user) {
checkDuplicatedByUsernameOrEmail(user.getUsername(), user.getEmail());
checkDuplicatedByUsername(user.getUsername());
checkDuplicatedByEmail(user.getEmail());

user.encodePassword(passwordEncoder);
return userRepository.save(user);
Expand All @@ -44,15 +45,19 @@ public Optional<User> findById(Long userId) {
return userRepository.findById(userId);
}

private void checkDuplicatedByUsernameOrEmail(Username username, Email email) {
private void checkDuplicatedByUsername(@Valid Username username) {
findByUsername(username)
.ifPresent(param -> {
throw new RuntimeException("already user username");
});
}

private void checkDuplicatedByEmail(@Valid Email email) {
findByEmail(email)
.ifPresent(param -> {
throw new RuntimeException("already user email");
});

}

private Optional<User> findByUsername(Username username) {
Expand Down

0 comments on commit 061f34e

Please sign in to comment.