-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🚀 Add CreditsURLProtocol, CreditsEndPoint, CreditsService, and CreditsResponse. * ✨ Add Credits API and Support with networking setup, and Credits model for displaying creators. * ✨ Add CreditsView to SettingsRow NavigationLink - Added CreditsView to the SettingsRow NavigationLink to enable navigation to the CreditsView from the Settings screen.
Showing
13 changed files
with
317 additions
and
46 deletions.
There are no files selected for viewing
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,35 @@ | ||
// | ||
// CreditsEndPoint.swift | ||
// | ||
// | ||
// Created by 홍승현 on 1/25/24. | ||
// | ||
|
||
import Foundation | ||
import Network | ||
|
||
// MARK: - CreditsEndPoint | ||
|
||
public enum CreditsEndPoint { | ||
case fetchCredits | ||
} | ||
|
||
// MARK: EndPoint | ||
|
||
extension CreditsEndPoint: EndPoint { | ||
public var method: HTTPMethod { | ||
.get | ||
} | ||
|
||
public var path: String { | ||
"/v2/credits" | ||
} | ||
|
||
public var parameters: HTTPParameter { | ||
.plain | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// CreditsService.swift | ||
// | ||
// | ||
// Created by 홍승현 on 1/31/24. | ||
// | ||
|
||
import Entity | ||
import Foundation | ||
import Network | ||
|
||
// MARK: - CreditsServiceRepresentable | ||
|
||
public protocol CreditsServiceRepresentable { | ||
func fetchCredits() async throws -> Credits | ||
} | ||
|
||
// MARK: - CreditsService | ||
|
||
public struct CreditsService { | ||
private let network: Networking | ||
|
||
public init(network: Networking) { | ||
self.network = network | ||
} | ||
} | ||
|
||
// MARK: CreditsServiceRepresentable | ||
|
||
extension CreditsService: CreditsServiceRepresentable { | ||
public func fetchCredits() async throws -> Credits { | ||
let response: CreditsResponse = try await network.request(with: CreditsEndPoint.fetchCredits) | ||
return Credits(dto: response) | ||
} | ||
} | ||
|
||
private extension Credits { | ||
init(dto: CreditsResponse) { | ||
self.init( | ||
title: dto.title, | ||
body: dto.body, | ||
date: dto.date | ||
) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
APIService/Sources/CreditsAPI/Responses/CreditsResponse.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,17 @@ | ||
// | ||
// CreditsResponse.swift | ||
// | ||
// | ||
// Created by 홍승현 on 1/31/24. | ||
// | ||
|
||
import Entity | ||
import Foundation | ||
|
||
// MARK: - ProductResponse | ||
|
||
struct CreditsResponse: Decodable { | ||
let title: String | ||
let body: String | ||
let date: Date | ||
} |
47 changes: 47 additions & 0 deletions
47
APIService/Sources/CreditsAPISupport/CreditsURLProtocol.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,47 @@ | ||
// | ||
// CreditsURLProtocol.swift | ||
// | ||
// | ||
// Created by 홍승현 on 1/25/24. | ||
// | ||
|
||
import CreditsAPI | ||
import Foundation | ||
import Network | ||
|
||
public final class CreditsURLProtocol: URLProtocol { | ||
private lazy var mockData: [String: Data?] = [ | ||
CreditsEndPoint.fetchCredits.path: loadMockData(fileName: "CreditsResponse"), | ||
] | ||
|
||
override public class func canInit(with _: URLRequest) -> Bool { | ||
true | ||
} | ||
|
||
override public class func canonicalRequest(for request: URLRequest) -> URLRequest { | ||
request | ||
} | ||
|
||
override public func startLoading() { | ||
defer { client?.urlProtocolDidFinishLoading(self) } | ||
if let url = request.url, | ||
let mockData = mockData[url.path(percentEncoded: true)], | ||
let data = mockData, | ||
let response = HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: nil) { | ||
client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed) | ||
client?.urlProtocol(self, didLoad: data) | ||
} else { | ||
client?.urlProtocol(self, didFailWithError: NetworkError.urlError) | ||
} | ||
} | ||
|
||
override public func stopLoading() {} | ||
|
||
private func loadMockData(fileName: String) -> Data? { | ||
guard let url = Bundle.module.url(forResource: fileName, withExtension: "json") | ||
else { | ||
return nil | ||
} | ||
return try? Data(contentsOf: url) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
APIService/Sources/CreditsAPISupport/Mocks/CreditsResponse.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"title": "만든 사람들", | ||
"body": "편행을 함께 만든 사람들을 소개합니다.\r\n\r\n기획/디자인\r\n- 박상훈, 홍승현\r\n\r\n개발\r\n- 홍승현과 아이들\r\n\r\n다국어 지원\r\n- 영어\r\n- 일본어", | ||
"date": "2024-03-20T01:07:55Z" | ||
} |
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,26 @@ | ||
// | ||
// Credits.swift | ||
// | ||
// | ||
// Created by 홍승현 on 3/22/24. | ||
// | ||
|
||
import Foundation | ||
|
||
/// `만든사람들`을 보여주는 크레딧 장면에서 사용될 엔티티 모델 | ||
public struct Credits { | ||
/// 크레딧 제목 | ||
public let title: String | ||
|
||
/// 크레딧 내용 | ||
public let body: String | ||
|
||
/// 크레딧 생성 날짜 | ||
public let date: Date | ||
|
||
public init(title: String, body: String, date: Date) { | ||
self.title = title | ||
self.body = body | ||
self.date = date | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
PyeonHaeng-iOS/Sources/Scenes/SettingsScene/Credits/CreditsView.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,29 @@ | ||
// | ||
// CreditsView.swift | ||
// PyeonHaeng-iOS | ||
// | ||
// Created by 홍승현 on 3/22/24. | ||
// | ||
|
||
import DesignSystem | ||
import SwiftUI | ||
|
||
struct CreditsView: View { | ||
@Environment(\.injected) private var container | ||
@State private var content: String = "" | ||
|
||
var body: some View { | ||
MarkdownView(content: content) | ||
.navigationTitle("Credits") | ||
.onAppear { | ||
Task { | ||
let credits = try await container.services.creditsService.fetchCredits() | ||
content = credits.body | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
SettingsView() | ||
} |
Oops, something went wrong.