Skip to content

Commit

Permalink
[feat] #121 Version Network API ๊ตฌ์„ฑ
Browse files Browse the repository at this point in the history
- ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์•ฑ์Šคํ† ์–ด์— ์žˆ๋Š” ์ตœ์‹  ๋ฒ„์ „์„ ๋ฐ›์•„์˜ด
- ๊ตฌํ˜„์š”์ฒญํ–ˆ๋Š”๋ฐ... ์•„์ง ๋ฏธ์‚ฌ์šฉ์ž„
  • Loading branch information
stealmh committed Sep 11, 2024
1 parent 99d72a7 commit 0b40c17
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Projects/CoreKit/Sources/Data/DTO/Version/VersionResponse.swift
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 Projects/CoreKit/Sources/Data/Network/Version/VersionClient.swift
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 }
)
}()
}

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"]
}
}
1 change: 1 addition & 0 deletions Projects/Util/Sources/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum Constants {
public static let contentPath: String = "/api/v1/content"
public static let remindPath: String = "api/v1/remind"
public static let alertPath: String = "/api/v1/alert"
public static let versionPath: String = "/api/v1/version"

public static let ๊ณต์ง€์‚ฌํ•ญ_์ฃผ์†Œ: URL = URL(string: "https://www.notion.so/POKIT-d97c81534b354cfebe677fbf1fbfe2b2")!
public static let ์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_์ฃผ์†Œ: URL = URL(string: "https://www.notion.so/3bddcd6fd00043abae6b92a50c39b132?pvs=4")!
Expand Down

0 comments on commit 0b40c17

Please sign in to comment.