Skip to content

[Refactoring] Starlink -> Moya 교체 작업 #185

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

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

junlight94
Copy link
Collaborator

@junlight94 junlight94 commented Apr 26, 2025

변경 유형

  • 버그 수정
  • 새로운 기능
  • 리팩토링
  • 문서 업데이트

변경 사항

  • Moya 교체 작업

관련링크 (JIRA)

관련 로그, 스크린샷

작업전 작업후
작업전 작업후

@junlight94 junlight94 added the 🛠️ Refactoring 리펙토링 레이블입니다. label Apr 26, 2025
@junlight94 junlight94 requested a review from a team April 26, 2025 09:26
@junlight94 junlight94 self-assigned this Apr 26, 2025
Comment on lines +22 to +27
let networkEventMonitor = NetworkEventMonitor()
let tokenCredential = TokenAuthenticationCredential()
let authenticatorInterceptor = AuthenticationInterceptor(
authenticator: TokenAuthenticator(),
credential: tokenCredential
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TokenInterceptor 작업

AccessToken이 만료되면 자동으로 갱신 받아서 Token 교체

Comment on lines +40 to +52
static func plain<T: TargetType>() -> MoyaProvider<T> {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 10 // 요청에 대한 타임아웃 10초
configuration.timeoutIntervalForResource = 10 // 리소스에 대한 타임아웃 10초

let networkEventMonitor = NetworkEventMonitor()
let session = Session(
configuration: configuration,
eventMonitors: [networkEventMonitor]
)

return MoyaProvider<T>(session: session)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

로그인 전 인증이 필요없는 요청의 provider


import Alamofire

final class NetworkEventMonitor: EventMonitor {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Network 통신 Logger

이 로그 때문에 다른 로그가 잘 안보인다면 나중에 삭제해도 괜춘

Comment on lines +12 to +18
public enum NetworkError: Error {
case underlying(Response)
case failure(Error)
case decoding
case unknown
case tokenEmpty
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네트워크 레이어 에러 정의 (추후 고도화 필요해유)

public extension TargetType {
// Header 기본 구현
var headers: [String: String]? {
Headers.common
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

매번 헤더 넣기 귀찮아서 TargetType 기본 구현으로 빼놨어요

Comment on lines +18 to +20
private var tokenRepository: TokenRepository {
ClogDI.container.resolve(TokenRepository.self)!
}
Copy link
Collaborator Author

@junlight94 junlight94 Apr 26, 2025

Choose a reason for hiding this comment

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

NetworkLayer에서 DataLayer를 몰라요
그래서 Domain에 TokenRepository 인터페이스 만들어서 의존성 역전 시켰어요

with response: HTTPURLResponse,
failDueToAuthenticationError error: any Error
) -> Bool {
return response.statusCode == 401
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

401일 때 인터셉터 발동

Comment on lines +58 to +59
NotificationCenter.default.post(name: .didKickOut, object: nil)
completion(.failure(failure))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

리프레시 실패시 kickout

Comment on lines +71 to +73
let token = try await tokenRepository.refresh(refreshToken)
tokenRepository.saveToken(token)
completion(.success(Credential()))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

refresh 토큰 재발급 및 저장

import Foundation
import Moya

public extension Encodable {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

queryParameter 넣을 때 항상 [String: Any] 형태로 변환해서 넣는 부분이 코드가 길어져서

queryParameter를 Encodable 객체로 받아서 사용해서
request.toSafeRequestParameter() 이 한줄로 끝낼 수 있도록 작업해놨어요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

파싱에 실패한다면 .requestPlain으로 리턴해요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ Refactoring 리펙토링 레이블입니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant