Add networking layer and wire up v9 login flow with unit tests.

Introduce APIClient/AuthAPI, complete login with multi-account selection, and polish the login card UI with shadow and keyboard dismiss.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-06 15:33:34 +08:00
parent b7d74905b7
commit 699f1ba7c4
21 changed files with 2387 additions and 18 deletions

View File

@ -0,0 +1,53 @@
//
// APIRequest.swift
// suixinkan
//
import Foundation
/// HTTP
enum HTTPMethod: String {
case get = "GET"
case post = "POST"
case put = "PUT"
case delete = "DELETE"
}
/// API Header
nonisolated struct APIRequest<Response: Decodable> {
var method: HTTPMethod
var path: String
var queryItems: [URLQueryItem]
var headers: [String: String]
var body: AnyEncodable?
/// API AnyEncodable
init<Body: Encodable>(
method: HTTPMethod,
path: String,
queryItems: [URLQueryItem] = [],
headers: [String: String] = [:],
body: Body? = Optional<EmptyPayload>.none
) {
self.method = method
self.path = path
self.queryItems = queryItems
self.headers = headers
self.body = body.map(AnyEncodable.init)
}
}
/// Encodable APIRequest
nonisolated struct AnyEncodable: Encodable, Sendable {
private let encodeValue: @Sendable (Encoder) throws -> Void
init<Value: Encodable>(_ value: Value) {
encodeValue = { encoder in
try value.encode(to: encoder)
}
}
func encode(to encoder: Encoder) throws {
try encodeValue(encoder)
}
}