Load role-permission on first visit to drive menus, role-based layout, store card, and location reporting with account-scoped persistence and unit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
1.6 KiB
Swift
50 lines
1.6 KiB
Swift
//
|
||
// NetworkServices.swift
|
||
// suixinkan
|
||
//
|
||
|
||
import Foundation
|
||
|
||
@MainActor
|
||
/// 全局网络依赖容器,集中提供 APIClient 与各业务 API。
|
||
final class NetworkServices {
|
||
static let shared = NetworkServices()
|
||
|
||
let apiClient: APIClient
|
||
let authAPI: AuthAPI
|
||
let profileAPI: ProfileAPI
|
||
let statisticsAPI: StatisticsAPI
|
||
let orderAPI: OrderAPI
|
||
let homeAPI: HomeAPI
|
||
let uploadAPI: UploadAPI
|
||
let ossUploadService: OSSUploadService
|
||
|
||
private init() {
|
||
let client = APIClient(environment: .current)
|
||
apiClient = client
|
||
authAPI = AuthAPI(client: client)
|
||
profileAPI = ProfileAPI(client: client)
|
||
statisticsAPI = StatisticsAPI(client: client)
|
||
orderAPI = OrderAPI(client: client)
|
||
homeAPI = HomeAPI(client: client)
|
||
uploadAPI = UploadAPI(client: client)
|
||
ossUploadService = OSSUploadService(configService: uploadAPI)
|
||
client.bindAuthTokenProvider {
|
||
let token = AppStore.shared.token.trimmingCharacters(in: .whitespacesAndNewlines)
|
||
return token.isEmpty ? nil : token
|
||
}
|
||
}
|
||
|
||
/// 测试专用初始化,允许注入 mock `APIClient`。
|
||
init(apiClient: APIClient) {
|
||
self.apiClient = apiClient
|
||
authAPI = AuthAPI(client: apiClient)
|
||
profileAPI = ProfileAPI(client: apiClient)
|
||
statisticsAPI = StatisticsAPI(client: apiClient)
|
||
orderAPI = OrderAPI(client: apiClient)
|
||
homeAPI = HomeAPI(client: apiClient)
|
||
uploadAPI = UploadAPI(client: apiClient)
|
||
ossUploadService = OSSUploadService(configService: uploadAPI)
|
||
}
|
||
}
|