Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#137] fix: findByOauthInfo Optional로 변경 #138

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading