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

Refactor [#95] OAuthService 리펙토링 #99

Merged
merged 7 commits into from
Nov 4, 2024
Merged

Conversation

HELLOHIDI
Copy link
Member

👾 작업 내용

기존에 Feature에 있던 OAuth 관련 로직을 레포지토리와 Service Layer을 통해서 분리했습니다

🚀 PR Point

  • OCP를 지키기 위해서 KakaoOAuthService, AppleOAuthService를 각각 만들어주기보단, OAuthServiceType이라는 변하지 않는 인증로직을 담은 Protocol을 선언하고 이를 채택하여 구현하도록 구현했습니다
public protocol OAuthServiceType {
    func authorize() -> AnyPublisher<String, HMHNetworkError.AuthError>
}

final class OAuthSerivce: OAuthServiceType {
    func authorize() -> AnyPublisher<String, HMHNetworkError.AuthError> {
        return Just("")
            .setFailureType(to: HMHNetworkError.AuthError.self)
            .eraseToAnyPublisher()
    }
}
  • 다른 Service 객체들과 다르게 OAuthSerivce는 유저가 버튼을 눌럿을 시 해당 서비스가 결정이 됩니다. 그래서 Factory타입을 주입밤으로써 인증이 시작될때 OAuthProviderType을 기준으로 알맞은 서비스 객체가 생성되도록 구현했습니다
public struct AuthRepository: AuthRepositoryType {
    
    private let authService: AuthServiceType
    private let oauthServiceFactory: OAuthServiceFactoryType
    
    init(authService: AuthServiceType, oauthServiceFactory: OAuthServiceFactoryType) {
        self.authService = authService
        self.oauthServiceFactory = oauthServiceFactory
    }
    
    public func authorize(_ serviceType: OAuthProviderType) -> AnyPublisher<String, Error> {
        let oauthService = oauthServiceFactory.makeOAuthService(for: serviceType)
        return oauthService.authorize()
            .map { $0 }
            .mapToGeneralError()
    }


public protocol OAuthServiceFactoryType {
    func makeOAuthService(for providerType: OAuthProviderType) -> OAuthServiceType
}

public class OAuthServiceFactory: OAuthServiceFactoryType {
    public init() {}

    public func makeOAuthService(for providerType: OAuthProviderType) -> OAuthServiceType {
        switch providerType {
        case .kakao:
            return OAuthKakaoService()
        case .apple:
            return OAuthAppleService()
        }
    }
}

📸 스크린샷

구현 내용 스크린샷
화면종류 파일첨부바람

✅ CheckList

  • 오류 없이 빌드되는지 확인
  • 로그용 print문 제거
  • 불필요한 주석 제거
  • 코드 컨벤션 확인

🔗 Issue

Resolved #95

Copy link
Member

@Zoe0929 Zoe0929 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다~!

Copy link
Member

@kim-seonwoo kim-seonwoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다 🙇

Comment on lines +17 to +34
@main
struct DataTestApp: App {
let kakaoAPIKey = Bundle.main.infoDictionary?["KAKAO_API_KEY"] as! String
init() {
KakaoSDK.initSDK(appKey: kakaoAPIKey)
}

var body: some Scene {
WindowGroup {
NetworkTestUI(
repository: AuthRepository(
authService: AuthService(requestHandler: RequestHandler()),
oauthServiceFactory: OAuthServiceFactory()
)
)
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

신기하고 어썸하군요..

Comment on lines +11 to +13
@frozen public enum HMHNetworkError: Error {
case invalidRequest(RequestError)
case invalidResponse(ResponseError)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거는 @Frozen 줄바꿈 안하신 이유가 궁금합니다!
(@Frozen 잘 안써봐서...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어 딱히 이유는 없는데 수정하도록 하겠습니다!

@HELLOHIDI HELLOHIDI merged commit 2aa20d6 into develop Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refactor] OAuthService 리펙토링
3 participants