Use existsByEmail

This commit is contained in:
hou27
2022-06-10 22:21:04 +09:00
parent f307710223
commit c5827d07fa
2 changed files with 8 additions and 12 deletions

View File

@@ -30,7 +30,8 @@ public class AuthServiceImpl implements AuthService {
@Transactional
public User signUp(UserSignUpRequest signUpReq) throws Exception {
System.out.println("signUpReq = " + signUpReq.toString());
if(this.isEmailExist(signUpReq.getEmail())) {
if(userRepository.existsByEmail(signUpReq.getEmail())) {
throw new Exception("Your Mail already Exist.");
}
User newUser = signUpReq.toUserEntity();
@@ -53,15 +54,4 @@ public class AuthServiceImpl implements AuthService {
throw new CustomException("Invalid credentials supplied", HttpStatus.UNPROCESSABLE_ENTITY);
}
}
/**
* 이메일 중복 여부를 확인
*
* @param email
* @return true | false
*/
private boolean isEmailExist(String email) {
Optional<User> byEmail = userRepository.findByEmail(email);
return !byEmail.isEmpty();
}
}

View File

@@ -10,5 +10,11 @@ public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByEmail(String email);
/**
* 이메일 중복 여부를 확인
*
* @param email
* @return true | false
*/
boolean existsByEmail(String email);
}