Files
汉秋 703078352c 从 iOS 17 Observation 迁移至 iOS 16 兼容的 Combine 架构
将最低部署版本降至 iOS 16,以 ObservableObject 替换 @Observable,新增导航与 UI 兼容层,并补充登录冒烟 UI 测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-26 10:16:35 +08:00

178 lines
7.0 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// ProjectAPI.swift
// suixinkan
//
// Created by Codex on 2026/6/24.
//
import Foundation
import Combine
/// 便 ViewModel
@MainActor
protocol ProjectServing {
///
func projectList(scenicId: Int, name: String?, page: Int, pageSize: Int) async throws -> ListPayload<PhotographerProjectItem>
///
func projectDetail(id: Int) async throws -> PhotographerProjectDetailResponse
///
func createProject(_ request: ProjectCreateRequest) async throws
///
func editProject(_ request: ProjectCreateRequest) async throws
///
func deleteProject(id: Int) async throws
///
func storeManagerScenicList(userId: String) async throws -> ListPayload<StoreManagerScenicItem>
///
func storeManagerProjectList(userId: String?, page: Int, pageSize: Int) async throws -> ListPayload<PhotographerProjectItem>
///
func storeManagerProjectDetail(id: Int) async throws -> PhotographerProjectDetailResponse
///
func storeManagerCreate(_ request: StoreManagerCreateRequest) async throws
///
func storeManagerOfflineCreate(_ request: StoreManagerOfflineCreateRequest) async throws
///
func storeManagerUpdate(_ request: StoreManagerUpdateRequest) async throws
///
func storeManagerOfflineUpdate(_ request: StoreManagerOfflineUpdateRequest) async throws
///
func storeManagerDeleteProject(id: Int) async throws
///
func storeAll() async throws -> ListPayload<StoreItem>
}
/// API
@MainActor
final class ProjectAPI: ProjectServing {
private let client: APIClient
/// API
init(client: APIClient) {
self.client = client
}
///
func projectList(scenicId: Int, name: String? = nil, page: Int = 1, pageSize: Int = 10) async throws -> ListPayload<PhotographerProjectItem> {
var query = [
URLQueryItem(name: "scenic_id", value: "\(scenicId)"),
URLQueryItem(name: "page", value: "\(max(page, 1))"),
URLQueryItem(name: "page_size", value: "\(max(pageSize, 1))")
]
if let name = name?.trimmingCharacters(in: .whitespacesAndNewlines), !name.isEmpty {
query.append(URLQueryItem(name: "name", value: name))
}
return try await client.send(
APIRequest(method: .get, path: "/api/yf-handset-app/photog/project/list", queryItems: query)
)
}
///
func projectDetail(id: Int) async throws -> PhotographerProjectDetailResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/project/info-view",
queryItems: [URLQueryItem(name: "id", value: "\(id)")]
)
)
}
///
func createProject(_ request: ProjectCreateRequest) async throws {
_ = try await client.send(
APIRequest(method: .post, path: "/api/yf-handset-app/photog/project/create", body: request)
) as EmptyPayload
}
///
func editProject(_ request: ProjectCreateRequest) async throws {
_ = try await client.send(
APIRequest(method: .post, path: "/api/yf-handset-app/photog/project/edit", body: request)
) as EmptyPayload
}
///
func deleteProject(id: Int) async throws {
_ = try await client.send(
APIRequest(method: .post, path: "/api/yf-handset-app/photog/project/delete", body: ProjectDeleteRequest(id: id))
) as EmptyPayload
}
///
func storeManagerScenicList(userId: String) async throws -> ListPayload<StoreManagerScenicItem> {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/store-manager/scenic-list",
queryItems: [URLQueryItem(name: "user_id", value: userId)]
)
)
}
///
func storeManagerProjectList(userId: String?, page: Int = 1, pageSize: Int = 20) async throws -> ListPayload<PhotographerProjectItem> {
var query = [
URLQueryItem(name: "page", value: "\(max(page, 1))"),
URLQueryItem(name: "page_size", value: "\(max(pageSize, 1))")
]
if let userId = userId?.trimmingCharacters(in: .whitespacesAndNewlines), !userId.isEmpty {
query.append(URLQueryItem(name: "user_id", value: userId))
}
return try await client.send(
APIRequest(method: .get, path: "/api/app/store-manager/list", queryItems: query)
)
}
///
func storeManagerProjectDetail(id: Int) async throws -> PhotographerProjectDetailResponse {
try await client.send(
APIRequest(method: .get, path: "/api/app/store-manager/detail", queryItems: [URLQueryItem(name: "id", value: "\(id)")])
)
}
///
func storeManagerCreate(_ request: StoreManagerCreateRequest) async throws {
_ = try await client.send(APIRequest(method: .post, path: "/api/app/store-manager/create", body: request)) as EmptyPayload
}
///
func storeManagerOfflineCreate(_ request: StoreManagerOfflineCreateRequest) async throws {
_ = try await client.send(APIRequest(method: .post, path: "/api/app/store-manager/offline-create", body: request)) as EmptyPayload
}
///
func storeManagerUpdate(_ request: StoreManagerUpdateRequest) async throws {
_ = try await client.send(APIRequest(method: .post, path: "/api/app/store-manager/update", body: request)) as EmptyPayload
}
///
func storeManagerOfflineUpdate(_ request: StoreManagerOfflineUpdateRequest) async throws {
_ = try await client.send(APIRequest(method: .post, path: "/api/app/store-manager/offline-update", body: request)) as EmptyPayload
}
///
func storeManagerDeleteProject(id: Int) async throws {
_ = try await client.send(
APIRequest(method: .post, path: "/api/app/store-manager/delete", body: ProjectDeleteRequest(id: id))
) as EmptyPayload
}
///
func storeAll() async throws -> ListPayload<StoreItem> {
try await client.send(APIRequest(method: .get, path: "/api/app/store/all"))
}
}