refactor: findNotDeletedUserByEmail 메소드 추가

This commit is contained in:
dongHyo
2022-05-27 18:26:49 +09:00
parent 6259218422
commit 34bbe0ec7f

View File

@@ -25,16 +25,9 @@ public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
@Override
public User login(LoginDTO loginDto) {
Optional<User> optionalUser = userRepository.findByEmailAndIsDeletedFalse(loginDto.getEmail());
if (optionalUser.isEmpty()) {
log.error("존재하지 않는 이메일 입니다. :: {}", loginDto);
throw new NotFoundEmailException();
}
User user = optionalUser.get();
User user = findNotDeletedUserByEmail(loginDto.getEmail());
user.checkPassword(loginDto);
return user;
}
@@ -56,7 +49,7 @@ public class UserServiceImpl implements UserService {
public User delete(@Valid DeleteUserDTO deleteUserDto) {
Optional<User> optionalUser = userRepository.findByEmail(deleteUserDto.getEmail());
if (optionalUser.isEmpty()) {
log.error("존재하지 않는 이메일 입니다. :: {}", deleteUserDto);
log.error("존재하지 않는 이메일 입니다. :: {}", deleteUserDto.getEmail());
throw new NotFoundEmailException();
}
@@ -67,14 +60,17 @@ public class UserServiceImpl implements UserService {
@Override
@Transactional
public User changePassword(@Valid ChangePasswordDTO changePasswordDto) {
Optional<User> optionalUser = userRepository.findByEmailAndIsDeletedFalse(changePasswordDto.getEmail());
if (optionalUser.isEmpty()) {
log.error("존재하지 않는 이메일 입니다. :: {}", changePasswordDto);
throw new NotFoundEmailException();
}
User user = optionalUser.get();
User user = findNotDeletedUserByEmail(changePasswordDto.getEmail());
return user.changePassword(changePasswordDto);
}
private User findNotDeletedUserByEmail(String email) {
Optional<User> optionalUser = userRepository.findByEmailAndIsDeletedFalse(email);
if (optionalUser.isEmpty()) {
log.error("존재하지 않는 이메일 입니다. :: {}", email);
throw new NotFoundEmailException();
}
return optionalUser.get();
}
}