Skip to content

Commit

Permalink
refactor(auth): null처리 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
qlido committed Apr 15, 2024
1 parent ce8397b commit 0a97bd5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<User, Long> {
Optional<User> findByEmail(String email);
User findByEmail(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 0a97bd5

Please sign in to comment.