-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: OAuth 클래스에 전략 패턴 적용 #432
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
Merged
nayonsoso
merged 4 commits into
solid-connection:develop
from
nayonsoso:refactor/431-adjust-strategy-pattern-oauth
Aug 11, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
src/main/java/com/example/solidconnection/auth/service/oauth/AppleOAuthService.java
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/main/java/com/example/solidconnection/auth/service/oauth/KakaoOAuthService.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/solidconnection/auth/service/oauth/OAuthClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.example.solidconnection.auth.service.oauth; | ||
|
|
||
| import com.example.solidconnection.auth.dto.oauth.OAuthUserInfoDto; | ||
| import com.example.solidconnection.siteuser.domain.AuthType; | ||
|
|
||
| public interface OAuthClient { | ||
|
|
||
| OAuthUserInfoDto getUserInfo(String code); | ||
|
|
||
| AuthType getAuthType(); | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/example/solidconnection/auth/service/oauth/OAuthClientMap.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.example.solidconnection.auth.service.oauth; | ||
|
|
||
| import com.example.solidconnection.common.exception.CustomException; | ||
| import com.example.solidconnection.common.exception.ErrorCode; | ||
| import com.example.solidconnection.siteuser.domain.AuthType; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class OAuthClientMap { | ||
|
|
||
| private final Map<AuthType, OAuthClient> oauthClientMap; | ||
|
|
||
| public OAuthClientMap(List<OAuthClient> oAuthClientList) { | ||
| this.oauthClientMap = oAuthClientList.stream() | ||
| .collect(Collectors.toMap(OAuthClient::getAuthType, Function.identity())); | ||
| } | ||
|
|
||
| public OAuthClient getOAuthClient(AuthType authType) { | ||
| OAuthClient oauthClient = oauthClientMap.get(authType); | ||
| if (oauthClient == null) { | ||
| throw new CustomException( | ||
| ErrorCode.NOT_DEFINED_ERROR, | ||
| "처리할 수 있는 OAuthClient가 없습니다. authType: " + authType.name() | ||
| ); | ||
| } | ||
| return oauthClient; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/java/com/example/solidconnection/auth/service/oauth/OAuthClientMapTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.example.solidconnection.auth.service.oauth; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatCode; | ||
| import static org.junit.jupiter.api.Assertions.assertAll; | ||
| import static org.mockito.BDDMockito.given; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| import com.example.solidconnection.common.exception.CustomException; | ||
| import com.example.solidconnection.common.exception.ErrorCode; | ||
| import com.example.solidconnection.siteuser.domain.AuthType; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| @DisplayName("OAuthClientMap 테스트") | ||
| class OAuthClientMapTest { | ||
|
|
||
| @Test | ||
| void AuthType에_해당하는_Client를_반환한다() { | ||
| // given | ||
| OAuthClient appleClient = mock(OAuthClient.class); | ||
| OAuthClient kakaoClient = mock(OAuthClient.class); | ||
| given(appleClient.getAuthType()).willReturn(AuthType.APPLE); | ||
| given(kakaoClient.getAuthType()).willReturn(AuthType.KAKAO); | ||
|
|
||
| OAuthClientMap oAuthClientMap = new OAuthClientMap( | ||
| List.of(appleClient, kakaoClient) | ||
| ); | ||
|
|
||
| // when & then | ||
| assertAll( | ||
| () -> assertThat(oAuthClientMap.getOAuthClient(AuthType.APPLE)).isEqualTo(appleClient), | ||
| () -> assertThat(oAuthClientMap.getOAuthClient(AuthType.KAKAO)).isEqualTo(kakaoClient) | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void AuthType에_매칭되는_Client가_없으면_예외가_발생한다() { | ||
| // given | ||
| OAuthClient appleClient = mock(OAuthClient.class); | ||
| given(appleClient.getAuthType()).willReturn(AuthType.APPLE); | ||
|
|
||
| OAuthClientMap oAuthClientMap = new OAuthClientMap( | ||
| List.of(appleClient) | ||
| ); | ||
|
|
||
| // when & then | ||
| assertThatCode(() -> oAuthClientMap.getOAuthClient(AuthType.KAKAO)) | ||
| .isInstanceOf(CustomException.class) | ||
| .hasMessageContaining(ErrorCode.NOT_DEFINED_ERROR.getMessage()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자식이 부모의 의존성을 주입하는 코드가 없어졌습니다🎉