Skip to content

Commit

Permalink
refactor(auth): OAuth 유저 등록 로직 리팩토링
Browse files Browse the repository at this point in the history
- `registerOAuthUser` 메서드 제거 및 `SignUpUseCase`로 대체
- `RegisterUserUseCase`와 `OAuthInfoRegistrar` 종속성 제거
- OAuth 유저 등록과 관련된 책임을 `SignUpUseCase`로 위임
  • Loading branch information
m-a-king committed Jan 23, 2025
1 parent c836aa9 commit f228675
Showing 1 changed file with 3 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@
import com.somemore.global.auth.oauth.converter.OAuthResponseConverter;
import com.somemore.global.auth.oauth.domain.CommonOAuthInfo;
import com.somemore.global.auth.oauth.domain.CustomOAuth2User;
import com.somemore.global.auth.oauth.registrar.OAuthInfoRegistrar;
import com.somemore.global.auth.oauth.service.OAuthInfoQueryService;
import com.somemore.user.domain.User;
import com.somemore.user.domain.UserRole;
import com.somemore.user.usecase.RegisterUserUseCase;
import com.somemore.global.auth.sign.up.SignUpUseCase;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional
public class OAuthUserProcessorImpl implements OAuthUserProcessor {

private final OAuthResponseConverter oauthResponseConverter;
private final OAuthInfoChecker oauthInfoChecker;
private final OAuthInfoRegistrar oauthInfoRegistrar;
private final RegisterUserUseCase registerUserUseCase;
private final OAuthInfoQueryService oAuthInfoQueryService;
private final SignUpUseCase signUpUseCase;

@Override
public UUID fetchUserIdByOAuthUser(CustomOAuth2User oauthUser) {
Expand All @@ -36,29 +30,12 @@ public UUID fetchUserIdByOAuthUser(CustomOAuth2User oauthUser) {

private UUID findUserIdByOAuthInfo(CommonOAuthInfo oauthInfo) {
if (isNewUser(oauthInfo)) {
User user = registerOAuthUser(oauthInfo);
return user.getId();
signUpUseCase.signUpOAuthUser(oauthInfo);
}
return oAuthInfoQueryService.getUserIdByCommonOAuthInfo(oauthInfo);
}

private User registerOAuthUser(CommonOAuthInfo oauthInfo) {
User user = registerUser(oauthInfo);
registerOAuthInfo(user, oauthInfo);
// TODO 봉사자 등록 이벤트 발행

return user;
}

private boolean isNewUser(CommonOAuthInfo oauthInfo) {
return !oauthInfoChecker.doesUserExist(oauthInfo.provider(), oauthInfo.oauthId());
}

private User registerUser(CommonOAuthInfo oauthInfo) {
return registerUserUseCase.registerOAuthUser(oauthInfo, UserRole.getOAuthUserDefaultRole());
}

private void registerOAuthInfo(User user, CommonOAuthInfo oauthInfo) {
oauthInfoRegistrar.register(user, oauthInfo);
}
}

0 comments on commit f228675

Please sign in to comment.