From 034edaea3ac6fdc2e0990fa29d7a62a9622525a4 Mon Sep 17 00:00:00 2001 From: nkhanh44 Date: Wed, 4 Oct 2023 22:14:28 +0700 Subject: [PATCH] [#515] Refactor NetworkAPIProtocol and move them to shared folder --- .../NetworkAPI/Core/NetworkAPIProtocol.swift | 34 ---------------- .../Sources/Data/NetworkAPI/NetworkAPI.swift | 26 ------------- .../NetworkAPI/Core/NetworkAPIError.swift | 11 ------ .../Core/RequestConfiguration.swift | 39 ------------------- .../Data/NetworkAPI/Interceptors/.gitkeep | 0 .../Sources/Data/NetworkAPI/Models/.gitkeep | 0 .../NetworkAPI/RequestConfigurations/.gitkeep | 0 .../UIKit/Sources/Data/Repositories/.gitkeep | 0 .../NetworkAPI/Core/NetworkAPIError.swift | 0 .../NetworkAPI/Core/NetworkAPIProtocol.swift | 0 .../Core/RequestConfiguration.swift | 0 .../Data/NetworkAPI/Interceptors/.gitkeep | 0 .../Sources/Data/NetworkAPI/Models/.gitkeep | 0 .../Sources/Data/NetworkAPI/NetworkAPI.swift | 0 .../NetworkAPI/RequestConfigurations/.gitkeep | 0 .../Sources/Data/Repositories/.gitkeep | 0 16 files changed, 110 deletions(-) delete mode 100644 Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift delete mode 100644 Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/NetworkAPI.swift delete mode 100644 Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift delete mode 100644 Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift delete mode 100644 Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Interceptors/.gitkeep delete mode 100644 Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Models/.gitkeep delete mode 100644 Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep delete mode 100644 Tuist/Interfaces/UIKit/Sources/Data/Repositories/.gitkeep rename {Tuist/Interfaces/SwiftUI => {PROJECT_NAME}}/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift (100%) rename {Tuist/Interfaces/UIKit => {PROJECT_NAME}}/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift (100%) rename {Tuist/Interfaces/SwiftUI => {PROJECT_NAME}}/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift (100%) rename {Tuist/Interfaces/SwiftUI => {PROJECT_NAME}}/Sources/Data/NetworkAPI/Interceptors/.gitkeep (100%) rename {Tuist/Interfaces/SwiftUI => {PROJECT_NAME}}/Sources/Data/NetworkAPI/Models/.gitkeep (100%) rename {Tuist/Interfaces/UIKit => {PROJECT_NAME}}/Sources/Data/NetworkAPI/NetworkAPI.swift (100%) rename {Tuist/Interfaces/SwiftUI => {PROJECT_NAME}}/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep (100%) rename {Tuist/Interfaces/SwiftUI => {PROJECT_NAME}}/Sources/Data/Repositories/.gitkeep (100%) diff --git a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift deleted file mode 100644 index fb6a161d..00000000 --- a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// NetworkAPIProtocol.swift -// - -import Alamofire -import Combine - -protocol NetworkAPIProtocol { - - func performRequest( - _ configuration: RequestConfiguration, - for type: T.Type - ) -> AnyPublisher -} - -extension NetworkAPIProtocol { - - func request( - session: Session, - configuration: RequestConfiguration, - decoder: JSONDecoder - ) -> AnyPublisher { - return session.request( - configuration.url, - method: configuration.method, - parameters: configuration.parameters, - encoding: configuration.encoding, - headers: configuration.headers, - interceptor: configuration.interceptor - ) - .publishDecodable(type: T.self, decoder: decoder) - .value() - } -} diff --git a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/NetworkAPI.swift b/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/NetworkAPI.swift deleted file mode 100644 index 413a003c..00000000 --- a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/NetworkAPI.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// NetworkAPI.swift -// - -import Alamofire -import Combine - -final class NetworkAPI: NetworkAPIProtocol { - - private let decoder: JSONDecoder - - init(decoder: JSONDecoder = JSONDecoder()) { - self.decoder = decoder - } - - func performRequest( - _ configuration: RequestConfiguration, - for type: T.Type - ) -> AnyPublisher { - request( - session: Session(), - configuration: configuration, - decoder: decoder - ) - } -} diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift deleted file mode 100644 index 78c72199..00000000 --- a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift +++ /dev/null @@ -1,11 +0,0 @@ -// -// NetworkAPIError.swift -// - -import Foundation - -enum NetworkAPIError: Error { - - case generic - case dataNotFound -} diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift deleted file mode 100644 index 32ddb9d3..00000000 --- a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// RequestConfiguration.swift -// - -import Alamofire -import Foundation - -protocol RequestConfiguration { - - var baseURL: String { get } - - var endpoint: String { get } - - var method: HTTPMethod { get } - - var url: URLConvertible { get } - - var parameters: Parameters? { get } - - var encoding: ParameterEncoding { get } - - var headers: HTTPHeaders? { get } - - var interceptor: RequestInterceptor? { get } -} - -extension RequestConfiguration { - - var url: URLConvertible { - let url = URL(string: baseURL)?.appendingPathComponent(endpoint) - return url?.absoluteString ?? "\(baseURL)\(endpoint)" - } - - var parameters: Parameters? { nil } - - var headers: HTTPHeaders? { nil } - - var interceptor: RequestInterceptor? { nil } -} diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Interceptors/.gitkeep b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Interceptors/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Models/.gitkeep b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Models/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep b/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Tuist/Interfaces/UIKit/Sources/Data/Repositories/.gitkeep b/Tuist/Interfaces/UIKit/Sources/Data/Repositories/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift b/{PROJECT_NAME}/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift similarity index 100% rename from Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift rename to {PROJECT_NAME}/Sources/Data/NetworkAPI/Core/NetworkAPIError.swift diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift b/{PROJECT_NAME}/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift similarity index 100% rename from Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift rename to {PROJECT_NAME}/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift diff --git a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift b/{PROJECT_NAME}/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift similarity index 100% rename from Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift rename to {PROJECT_NAME}/Sources/Data/NetworkAPI/Core/RequestConfiguration.swift diff --git a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Interceptors/.gitkeep b/{PROJECT_NAME}/Sources/Data/NetworkAPI/Interceptors/.gitkeep similarity index 100% rename from Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Interceptors/.gitkeep rename to {PROJECT_NAME}/Sources/Data/NetworkAPI/Interceptors/.gitkeep diff --git a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Models/.gitkeep b/{PROJECT_NAME}/Sources/Data/NetworkAPI/Models/.gitkeep similarity index 100% rename from Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/Models/.gitkeep rename to {PROJECT_NAME}/Sources/Data/NetworkAPI/Models/.gitkeep diff --git a/Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/NetworkAPI.swift b/{PROJECT_NAME}/Sources/Data/NetworkAPI/NetworkAPI.swift similarity index 100% rename from Tuist/Interfaces/UIKit/Sources/Data/NetworkAPI/NetworkAPI.swift rename to {PROJECT_NAME}/Sources/Data/NetworkAPI/NetworkAPI.swift diff --git a/Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep b/{PROJECT_NAME}/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep similarity index 100% rename from Tuist/Interfaces/SwiftUI/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep rename to {PROJECT_NAME}/Sources/Data/NetworkAPI/RequestConfigurations/.gitkeep diff --git a/Tuist/Interfaces/SwiftUI/Sources/Data/Repositories/.gitkeep b/{PROJECT_NAME}/Sources/Data/Repositories/.gitkeep similarity index 100% rename from Tuist/Interfaces/SwiftUI/Sources/Data/Repositories/.gitkeep rename to {PROJECT_NAME}/Sources/Data/Repositories/.gitkeep