Skip to content

Commit

Permalink
[#137] fix: findByOauthInfo Optional로 변경 (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomo authored Nov 2, 2023
1 parent 102898c commit bc17132
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.todaysfail.domains.user.exception.UserNotFountException;
import com.todaysfail.domains.user.port.UserQueryPort;
import com.todaysfail.domains.user.repository.UserRepository;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -16,10 +17,8 @@ public class UserQueryAdapter implements UserQueryPort {
private final UserRepository userRepository;

@Override
public User findByOauthInfo(OauthInfo oauthInfo) {
return userRepository
.findByOauthInfo(oauthInfo)
.orElseThrow(() -> UserNotFountException.EXCEPTION);
public Optional<User> findByOauthInfo(OauthInfo oauthInfo) {
return userRepository.findByOauthInfo(oauthInfo);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.todaysfail.domains.user.domain.OauthInfo;
import com.todaysfail.domains.user.domain.User;
import java.util.Optional;

public interface UserQueryPort {
User findByOauthInfo(OauthInfo oauthInfo);
Optional<User> findByOauthInfo(OauthInfo oauthInfo);

Boolean existsByOauthInfo(OauthInfo oauthInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.todaysfail.domains.user.exception.UserNotFountException;
import com.todaysfail.domains.user.port.UserCommandPort;
import com.todaysfail.domains.user.port.UserQueryPort;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -41,12 +42,12 @@ public UserDetail queryUser(Long userId) {
@Transactional(noRollbackFor = UserNotFountException.class)
@RedissonLock(lockName = "개발용회원가입", identifier = "oauthInfo")
public User upsert(Profile profile, OauthInfo oauthInfo, FcmNotification fcmNotification) {
try {
return userQueryPort.findByOauthInfo(oauthInfo);
} catch (UserNotFountException e) {
Optional<User> userOptional = userQueryPort.findByOauthInfo(oauthInfo);
if (userOptional.isEmpty()) {
return userCommandPort.save(
User.registerNormalUser(profile, oauthInfo, fcmNotification));
}
return userOptional.get();
}

@Transactional
Expand Down

0 comments on commit bc17132

Please sign in to comment.