-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] #121 Version Network API ๊ตฌ์ฑ
- ์๋ฒ๋ก๋ถํฐ ์ฑ์คํ ์ด์ ์๋ ์ต์ ๋ฒ์ ์ ๋ฐ์์ด - ๊ตฌํ์์ฒญํ๋๋ฐ... ์์ง ๋ฏธ์ฌ์ฉ์
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
Projects/CoreKit/Sources/Data/DTO/Version/VersionResponse.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,16 @@ | ||
// | ||
// VersionResponse.swift | ||
// CoreKit | ||
// | ||
// Created by ๊น๋ฏผํธ on 9/10/24. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct VersionResponse: Decodable { | ||
public let recentVersion: String | ||
} | ||
|
||
extension VersionResponse { | ||
static let mock: Self = Self(recentVersion: "1.0.0") | ||
} |
42 changes: 42 additions & 0 deletions
42
Projects/CoreKit/Sources/Data/Network/Version/VersionClient.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,42 @@ | ||
// | ||
// VersionClient.swift | ||
// CoreKit | ||
// | ||
// Created by ๊น๋ฏผํธ on 9/10/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Dependencies | ||
import Moya | ||
|
||
// MARK: - Dependency Values | ||
extension DependencyValues { | ||
public var versionClient: VersionClient { | ||
get { self[VersionClient.self] } | ||
set { self[VersionClient.self] = newValue } | ||
} | ||
} | ||
/// ์๋์ ๊ด๋ จํ API๋ฅผ ์ฒ๋ฆฌํ๋ Client | ||
public struct VersionClient { | ||
public var ๋ฒ์ ์ฒดํฌ: @Sendable () async throws -> VersionResponse | ||
} | ||
|
||
extension VersionClient: DependencyKey { | ||
public static let liveValue: Self = { | ||
let nonProvider = MoyaProvider<VersionEndpoint>.buildNonToken() | ||
|
||
return Self( | ||
๋ฒ์ ์ฒดํฌ: { | ||
try await nonProvider.request(.๋ฒ์ ์ฒดํฌ) | ||
} | ||
) | ||
}() | ||
|
||
public static let previewValue: Self = { | ||
Self( | ||
๋ฒ์ ์ฒดํฌ: { .mock } | ||
) | ||
}() | ||
} | ||
|
46 changes: 46 additions & 0 deletions
46
Projects/CoreKit/Sources/Data/Network/Version/VersionEndpoint.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,46 @@ | ||
// | ||
// VersionEndpoint.swift | ||
// CoreKit | ||
// | ||
// Created by ๊น๋ฏผํธ on 9/10/24. | ||
// | ||
|
||
import Foundation | ||
import Util | ||
import Moya | ||
|
||
/// Version์ ์ํ Moya Endpoint | ||
public enum VersionEndpoint { | ||
case ๋ฒ์ ์ฒดํฌ | ||
} | ||
|
||
extension VersionEndpoint: TargetType { | ||
public var baseURL: URL { | ||
return Constants.serverURL.appendingPathComponent(Constants.versionPath, conformingTo: .url) | ||
} | ||
|
||
public var path: String { | ||
/// ํ์ฅ์ฑ์ ์ํด switch๋ฌธ์ผ๋ก ๋๋ | ||
switch self { | ||
case .๋ฒ์ ์ฒดํฌ: return "" | ||
} | ||
} | ||
|
||
public var method: Moya.Method { | ||
switch self { | ||
case .๋ฒ์ ์ฒดํฌ: | ||
return .get | ||
} | ||
} | ||
|
||
public var task: Moya.Task { | ||
switch self { | ||
case .๋ฒ์ ์ฒดํฌ: | ||
return .requestPlain | ||
} | ||
} | ||
|
||
public var headers: [String : String]? { | ||
["Content-Type": "application/json"] | ||
} | ||
} |
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