-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9b5099
commit ce88272
Showing
14 changed files
with
238 additions
and
6 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
Modules/Data/Sources/NetworkAPI/Core/NetworkAPIError.swift
This file contains 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 @@ | ||
// | ||
// NetworkAPIError.swift | ||
// | ||
|
||
import Foundation | ||
|
||
enum NetworkAPIError: Error { | ||
|
||
case generic | ||
case dataNotFound | ||
} |
33 changes: 33 additions & 0 deletions
33
Modules/Data/Sources/NetworkAPI/Core/NetworkAPIProtocol.swift
This file contains 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,33 @@ | ||
// | ||
// NetworkAPIProtocol.swift | ||
// | ||
|
||
import Alamofire | ||
|
||
protocol NetworkAPIProtocol { | ||
|
||
func performRequest<T: Decodable>( | ||
_ configuration: RequestConfiguration, | ||
for type: T.Type | ||
) async throws -> T | ||
} | ||
|
||
extension NetworkAPIProtocol { | ||
|
||
func request<T: Decodable>( | ||
session: Session, | ||
configuration: RequestConfiguration, | ||
decoder: JSONDecoder | ||
) async throws -> T { | ||
try await session.request( | ||
configuration.url, | ||
method: configuration.method, | ||
parameters: configuration.parameters, | ||
encoding: configuration.encoding, | ||
headers: configuration.headers, | ||
interceptor: configuration.interceptor | ||
) | ||
.serializingDecodable(T.self) | ||
.value | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Modules/Data/Sources/NetworkAPI/Core/RequestConfiguration.swift
This file contains 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,39 @@ | ||
// | ||
// 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 } | ||
} |
Empty file.
Empty file.
This file contains 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,25 @@ | ||
// | ||
// NetworkAPI.swift | ||
// | ||
|
||
import Alamofire | ||
|
||
final class NetworkAPI: NetworkAPIProtocol { | ||
|
||
private let decoder: JSONDecoder | ||
|
||
init(decoder: JSONDecoder = JSONDecoder()) { | ||
self.decoder = decoder | ||
} | ||
|
||
func performRequest<T: Decodable>( | ||
_ configuration: RequestConfiguration, | ||
for type: T.Type | ||
) async throws -> T { | ||
try await request( | ||
session: Session(), | ||
configuration: configuration, | ||
decoder: decoder | ||
) | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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,5 @@ | ||
// | ||
// UseCaseFactoryProtocol.swift | ||
// | ||
|
||
protocol UseCaseFactoryProtocol: AnyObject {} |
This file contains 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 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,33 @@ | ||
// | ||
// Modules.swift | ||
// ProjectDescriptionHelpers | ||
// | ||
// Created by Phong on 16/10/2023. | ||
// | ||
|
||
import ProjectDescription | ||
|
||
|
||
public enum Module: CaseIterable { | ||
|
||
case domain | ||
case data | ||
|
||
public var name: String { | ||
switch self { | ||
case .domain: | ||
return "Domain" | ||
case .data: | ||
return "Data" | ||
} | ||
} | ||
|
||
public var dependencies: [TargetDependency] { | ||
switch self { | ||
case .domain: | ||
return [] | ||
case .data: | ||
return [.target(name: Module.domain.name)] | ||
} | ||
} | ||
} |
This file contains 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