diff --git a/src/main/java/com/project/bumawiki/domain/auth/service/CommandAuthService.java b/src/main/java/com/project/bumawiki/domain/auth/service/CommandAuthService.java index b9a9d7e..91cc85c 100644 --- a/src/main/java/com/project/bumawiki/domain/auth/service/CommandAuthService.java +++ b/src/main/java/com/project/bumawiki/domain/auth/service/CommandAuthService.java @@ -28,10 +28,10 @@ public class CommandAuthService { public Token login(String authId) { User unknownUser = bsmLoginHandler.getUserByAuthId(authId); - User user = userReader.getByEmail(unknownUser.getEmail()); + User user = userReader.getNullableUserByEmail(unknownUser.getEmail()); if (user == null) { - userCreator.create(unknownUser); + user = userCreator.create(unknownUser); } else { userUpdater.update(user, unknownUser); } diff --git a/src/main/java/com/project/bumawiki/domain/user/domain/repository/UserRepository.java b/src/main/java/com/project/bumawiki/domain/user/domain/repository/UserRepository.java index 7451681..a129719 100644 --- a/src/main/java/com/project/bumawiki/domain/user/domain/repository/UserRepository.java +++ b/src/main/java/com/project/bumawiki/domain/user/domain/repository/UserRepository.java @@ -1,11 +1,9 @@ package com.project.bumawiki.domain.user.domain.repository; -import java.util.Optional; - import org.springframework.data.jpa.repository.JpaRepository; import com.project.bumawiki.domain.user.domain.User; public interface UserRepository extends JpaRepository { - Optional findByEmail(String email); + User findByEmail(String email); } diff --git a/src/main/java/com/project/bumawiki/domain/user/implementation/UserCreator.java b/src/main/java/com/project/bumawiki/domain/user/implementation/UserCreator.java index f2c9db7..393ab3d 100644 --- a/src/main/java/com/project/bumawiki/domain/user/implementation/UserCreator.java +++ b/src/main/java/com/project/bumawiki/domain/user/implementation/UserCreator.java @@ -11,7 +11,7 @@ public class UserCreator { private final UserRepository userRepository; - public void create(User user) { - userRepository.save(user); + public User create(User user) { + return userRepository.save(user); } } diff --git a/src/main/java/com/project/bumawiki/domain/user/implementation/UserReader.java b/src/main/java/com/project/bumawiki/domain/user/implementation/UserReader.java index e3be722..135c41a 100644 --- a/src/main/java/com/project/bumawiki/domain/user/implementation/UserReader.java +++ b/src/main/java/com/project/bumawiki/domain/user/implementation/UserReader.java @@ -17,7 +17,7 @@ public User getById(Long id) { return userRepository.findById(id).orElseThrow(() -> new BumawikiException(ErrorCode.USER_NOT_FOUND)); } - public User getByEmail(String email) { - return userRepository.findByEmail(email).orElseThrow(() -> new BumawikiException(ErrorCode.USER_NOT_FOUND)); + public User getNullableUserByEmail(String email) { + return userRepository.findByEmail(email); } }