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

Network [#55] BaseURL 설정 및 네트워크 세팅 #56

Merged
merged 3 commits into from
Jan 14, 2024

Conversation

Heyjooo
Copy link
Collaborator

@Heyjooo Heyjooo commented Jan 14, 2024

👻 PULL REQUEST

💻 작업한 내용

  • Info 설정
  • Config 파일 구현
  • Nerwork Error 파일 구현
  • BaseResponse 생성

💡 참고사항

📟 관련 이슈

2AC9FB1B2B4DE77400D31071 /* AgreementListCustomView.swift in Sources */,
2F17418A2B500CC20089FC4D /* HomeBottomsheetView.swift in Sources */,
3C01692A2B4DC82D0075334B /* DontBePopupView.swift in Sources */,
2A2671FF2B4C3AF0009D214F /* Publisher+UIControl.swift in Sources */,
3C4993672B4F2644002A99CF /* MyPageContentViewController.swift in Sources */,
3CEE4CC22B503F9E00F506AF /* DontBeCustomInfoView.swift in Sources */,
2A2845402B531F0A0023F9B5 /* BaseResponse.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

Choose a reason for hiding this comment

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

해당 코드 패치에는 다음과 같은 변경 사항이 있습니다:

  1. 파일 추가:

    • SocialLoginService.swift, BaseResponse.swift, SocialLoginResponseDTO.swift, SocialLoginRequestDTO.swift 파일이 소스에 추가되었습니다.
  2. 그룹 추가:

    • SocialLogin 그룹이 Network 그룹 안에 추가되었습니다.
    • DTOService 그룹이 SocialLogin 그룹 안에 추가되었습니다.

수정 사항 및 개선 제안은 제공하지 않았습니다.

@@ -20,7 +20,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
NSAttributedString.Key.foregroundColor: UIColor.donBlack
]

KakaoSDK.initSDK(appKey: Bundle.main.object(forInfoDictionaryKey: Config.Keys.Plist.nativeAppKey) as? String ?? "")
KakaoSDK.initSDK(appKey: Config.nativeAppKey)
return true
}

Choose a reason for hiding this comment

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

해당 코드 패치에 대한 간단한 코드 리뷰를 도와드리겠습니다. 버그 위험 및 개선 제안 사항을 언급하도록 하겠습니다:

  1. 해당 코드 패치는 AppDelegate 클래스 내의 application(_:didFinishLaunchingWithOptions:) 메서드에서 수행됩니다.
  2. 이 코드 패치에서는 KakaoSDK를 초기화하는 작업이 수행됩니다.
  3. 변경된 부분은 KakaoSDK.initSDK(appKey:) 메서드의 인수로 사용되는 앱 키입니다.
  4. 기존 코드에서는 NSBundle.main.object(forInfoDictionaryKey: Config.Keys.Plist.nativeAppKey)를 사용하여 앱 키 값을 가져왔지만, 변경된 코드에서는 Config.nativeAppKey를 사용합니다.

버그 위험:

  • 해당 코드 패치에 명시적인 버그 위험이 보이지 않습니다.

개선 제안:

  • 클래스 멤버인 Config.nativeAppKey은 미리 정의되어 있어야 합니다. nativeAppKey가 정의되지 않은 경우에 대비하는 방법을 고려해보세요.
  • Config.nativeAppKeynil이거나 유효하지 않을 경우에 대한 처리를 추가해보세요.
  • 다른 문제점이나 개선할 수 있는 사항은 제공된 정보만으로는 파악하기 어렵습니다. 전체 코드 범위 등 추가 정보를 제공한다면 더 자세한 도움을 드릴 수 있습니다.

self.window?.rootViewController = navigationController
} else if loadUserData()?.isOnboardingFinished == false {
let navigationController = UINavigationController(rootViewController: OnboardingViewController())
self.window?.rootViewController = navigationController
} else {
let navigationController = UINavigationController(rootViewController: LoginViewController(viewModel: LoginViewModel()))
let navigationController = UINavigationController(rootViewController: LoginViewController(viewModel: LoginViewModel(networkProvider: SocialLoginService())))
self.window?.rootViewController = navigationController
}
self.window?.makeKeyAndVisible()

Choose a reason for hiding this comment

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

아래는 코드 패치입니다. 지적해야 할 버그 위험 또는 개선 제안이 있다면 환영합니다:

@@ -19,20 +19,18 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
self.window?.rootViewController = SplashViewController()
self.window?.makeKeyAndVisible()

  • DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2.0) {
    -// let navigationController = UINavigationController(rootViewController: LoginViewController(viewModel: LoginViewModel()))
    -// let navigationController = UINavigationController(rootViewController: DontBeTabBarController())
  • DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0) {
    if loadUserData()?.isSocialLogined == true && loadUserData()?.isJoinedApp == true && loadUserData()?.isOnboardingFinished == true {
    let navigationController = UINavigationController(rootViewController: DontBeTabBarController())
    self.window?.rootViewController = navigationController
    } else if loadUserData()?.isJoinedApp == false {
  •        let navigationController = UINavigationController(rootViewController: LoginViewController(viewModel: LoginViewModel()))
    
  •        let navigationController = UINavigationController(rootViewController: LoginViewController(viewModel: LoginViewModel(networkProvider: SocialLoginService())))
           self.window?.rootViewController = navigationController
       } else if loadUserData()?.isOnboardingFinished == false {
           let navigationController = UINavigationController(rootViewController: OnboardingViewController())
           self.window?.rootViewController = navigationController
       } else {
    
  •        let navigationController = UINavigationController(rootViewController: LoginViewController(viewModel: LoginViewModel()))
    
  •        let navigationController = UINavigationController(rootViewController: LoginViewController(viewModel: LoginViewModel(networkProvider: SocialLoginService())))
           self.window?.rootViewController = navigationController
       }
       self.window?.makeKeyAndVisible()
    

코드 리뷰를 진행하겠습니다.

  1. DispatchTime 조정: 비동기적으로 실행되는 블록의 실행 시간을 2.0초에서 1.0초로 변경했습니다.

  2. LoginViewController 인스턴스화: LoginViewController 생성자에 viewModel 매개변수 외에도 networkProvider를 추가함으로써, LoginViewModel의 의존성을 SocialLoginService로 변경했습니다. 이렇게 함으로써 더 큰 유연성을 갖출 수 있습니다.

  3. 중복 코드 제거: 원래 코드에서 두 개의 동일한 브랜치에서 LoginViewController 인스턴스화를 사용했으므로 이를 통합하여 중복을 없앴습니다.

  4. 주석 처리된 코드 제거: LoginViewController와 DontBeTabBarController를 사용하는 네비게이션 컨트롤러를 생성하는 라인의 주석 처리된 코드를 삭제했습니다.

이 코드 패치를 통해 일부 버그 위험을 해결하고 코드 구조를 개선했습니다.

<true/>
</dict>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>LSApplicationQueriesSchemes</key>

Choose a reason for hiding this comment

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

해당 코드 패치에서는 NSAppTransportSecurityBASE_URL이 추가되었습니다.

향상사항:

  • NSAppTransportSecurity 딕셔너리에 NSAllowsArbitraryLoads 키가 추가되어, 앱이 모든 네트워크 연결을 허용하도록 설정됩니다. 이것은 보안상의 위험을 초래할 수 있으므로, 가능하면 특정 도메인만 허용하도록 변경하는 것이 좋습니다.
  • BASE_URL 키에는 $(BASE_URL) 문자열이 값으로 지정되어 있는데, 이는 변수 또는 환경변수의 값을 참조하는 것으로 보입니다. 값으로 실제 사용할 URL을 지정해야 합니다.

문제점:

  • 문제점은 없어 보입니다.

요약:

  • 네트워크 보안과 관련된 설정(NSAppTransportSecurity)을 조정할 필요가 있습니다.
  • BASE_URL 값을 서버의 주소로 지정해야 합니다.

let success: Bool
let message: String
let data: T?
}

Choose a reason for hiding this comment

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

해당 코드 패치는 큰 결함이 없어 보입니다. 다만, 한 가지 개선점을 제안드릴게요. 굳이 BaseResponse 구조체를 Decodable 프로토콜을 채택하도록 구현할 필요는 없습니다. 왜냐하면 BaseResponse의 속성 중 일부가 이미 Decodable이기 때문이에요. 따라서, 아래와 같이 수정하는 것이 더 간단하고 명확할 겁니다.

struct BaseResponse<T>: Decodable where T: Decodable {
    let status: Int
    let success: Bool
    let message: String
    let data: T?
}

이와 같이 수정하면 현재의 코드와 동일한 동작을 하지만, BaseResponse가 불필요하게 자기 자신을 추가적으로 해석하지 않아도 되므로 개선됩니다.

}
return key
}()
}

Choose a reason for hiding this comment

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

이 코드 패치는 Config라는 열거형과 Keys 안에 Plist라는 열거형이 정의되어 있습니다. 그리고 nativeAppKeybaseURL이라는 두 개의 속성도 추가되었습니다.

주의해야 할 부분은 nativeAppKeybaseURL의 값을 가져오는 부분입니다. Config에 해당하는 infoDictionary에서 Keys.Plist.nativeAppKeyKeys.Plist.baseURL에 해당하는 값을 가져옵니다. 하지만 해당 값이 없는 경우, fatalError를 발생시키며 "Base URL is not set in plist for this configuration"라는 메시지를 표시합니다.

개선 사항으로는 fatalError 대신 선택적인 반환을 사용하여 앱이 비정상 종료되지 않게 처리할 수 있습니다. 또한, 선택적인 반환을 위해 옵셔널 타입을 사용하면 유효하지 않은 속성이 있더라도 코드 실행을 계속할 수 있습니다.

아래는 개선된 코드의 예시입니다:

extension Config {
    static var nativeAppKey: String? {
        return Config.infoDictionary[Keys.Plist.nativeAppKey] as? String
    }
    
    static var baseURL: String? {
        return Config.infoDictionary[Keys.Plist.baseURL] as? String
    }
}

이렇게 구현하면 nativeAppKeybaseURL은 옵셔널 타입으로 선언되기 때문에 값이 없을 경우에도 안전하게 처리할 수 있습니다.

Copy link
Collaborator

@yeonsu0-0 yeonsu0-0 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

@boogios boogios left a comment

Choose a reason for hiding this comment

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

P3
어려운 로그인 부분 구현하느라 고생하셨습니다!!! 코드 너무 깔끔하네요~~

case .internalServerError: return "SERVER_ERROR"
case .unknownError: return "UNKNOWN_ERROR"
}
}
Copy link
Member

Choose a reason for hiding this comment

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

P3
에러 코드 정리 고생하셨어요~~

@@ -134,7 +136,7 @@ extension OnboardingView {
}

DispatchQueue.main.async {
if loadUserData()?.isNotFirstUser == true {
if self.isFirstUser == false {
Copy link
Member

Choose a reason for hiding this comment

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

P3
체크하는 방식 너무 좋네요!

@Heyjooo Heyjooo merged commit 6317b25 into develop Jan 14, 2024
1 check passed
@Heyjooo Heyjooo deleted the network/#55/baseURL branch January 14, 2024 08:25
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.

[Network] BaseURL 설정 및 네트워크 세팅
3 participants