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

201 lines
7.7 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.

//
// ScenicQueueAPI.swift
// suixinkan
//
// Created by Codex on 2026/6/25.
//
import Foundation
import Combine
/// token
@MainActor
protocol ScenicQueueServing: AnyObject {
func scenicQueueStats(scenicId: Int, scenicSpotId: Int) async throws -> ScenicQueueStatsData
func scenicQueueHome(scenicId: Int, scenicSpotId: Int, type: Int, page: Int, pageSize: Int) async throws -> ScenicQueueHomeData
func socketToken() async throws -> SocketTokenResponse
func scenicQueueCall(id: Int64) async throws -> ScenicQueueCallData
func scenicQueuePass(id: Int64) async throws -> ScenicQueuePassData
func scenicQueueFinish(id: Int64) async throws -> ScenicQueueFinishData
func scenicQueueRequeueInsertBefore(recordId: Int64, operatorId: Int) async throws
func scenicQueueUserMark(_ request: ScenicQueueUserMarkRequest) async throws
func scenicQueueSetting(scenicId: Int, scenicSpotId: Int?) async throws -> ScenicQueueSettingData
func scenicQueueSaveSetting(_ request: ScenicQueueSaveSettingRequest) async throws
func scenicQueueShootQueueQRCode(scenicId: Int, scenicSpotId: Int) async throws -> ScenicQueueShootQueueQRCodeData
func scenicQueueSettingChangeLog(scenicId: Int, scenicSpotId: Int?, page: Int, pageSize: Int) async throws -> ScenicQueueSettingChangeLogData
}
@MainActor
/// API `/api/app/scenic-queue`
final class ScenicQueueAPI {
private let client: APIClient
/// API
init(client: APIClient) {
self.client = client
}
///
func scenicQueueStats(scenicId: Int, scenicSpotId: Int) async throws -> ScenicQueueStatsData {
do {
return try await client.send(
APIRequest(
method: .get,
path: "/api/app/scenic-queue/queue-stats",
queryItems: [
URLQueryItem(name: "scenic_id", value: String(scenicId)),
URLQueryItem(name: "scenic_spot_id", value: String(scenicSpotId))
]
)
)
} catch APIError.emptyData {
return ScenicQueueStatsData()
}
}
///
func scenicQueueHome(
scenicId: Int,
scenicSpotId: Int,
type: Int,
page: Int = 1,
pageSize: Int = 20
) async throws -> ScenicQueueHomeData {
do {
return try await client.send(
APIRequest(
method: .get,
path: "/api/app/scenic-queue/home",
queryItems: [
URLQueryItem(name: "scenic_id", value: String(scenicId)),
URLQueryItem(name: "scenic_spot_id", value: String(scenicSpotId)),
URLQueryItem(name: "type", value: String(type)),
URLQueryItem(name: "page", value: String(max(page, 1))),
URLQueryItem(name: "page_size", value: String(max(pageSize, 1)))
]
)
)
} catch APIError.emptyData {
return ScenicQueueHomeData()
}
}
/// WebSocket token
func socketToken() async throws -> SocketTokenResponse {
try await client.send(APIRequest(method: .get, path: "/api/app/socket-token"))
}
///
func scenicQueueCall(id: Int64) async throws -> ScenicQueueCallData {
do {
return try await client.send(
APIRequest(method: .post, path: "/api/app/scenic-queue/call", body: ScenicQueueActionRequest(id: id))
)
} catch APIError.emptyData {
return ScenicQueueCallData(id: id)
}
}
///
func scenicQueuePass(id: Int64) async throws -> ScenicQueuePassData {
do {
return try await client.send(
APIRequest(method: .post, path: "/api/app/scenic-queue/pass", body: ScenicQueueActionRequest(id: id))
)
} catch APIError.emptyData {
return ScenicQueuePassData(id: id)
}
}
///
func scenicQueueFinish(id: Int64) async throws -> ScenicQueueFinishData {
do {
return try await client.send(
APIRequest(method: .post, path: "/api/app/scenic-queue/finish", body: ScenicQueueActionRequest(id: id))
)
} catch APIError.emptyData {
return ScenicQueueFinishData(id: id)
}
}
///
func scenicQueueRequeueInsertBefore(recordId: Int64, operatorId: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/app/scenic-queue/requeue-insert-before",
body: ScenicQueueRequeueInsertBeforeRequest(recordId: recordId, operatorId: operatorId)
)
)
}
/// /
func scenicQueueUserMark(_ request: ScenicQueueUserMarkRequest) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/scenic-queue/user-mark", body: request)
)
}
///
func scenicQueueSetting(scenicId: Int, scenicSpotId: Int?) async throws -> ScenicQueueSettingData {
var query = [URLQueryItem(name: "scenic_id", value: String(scenicId))]
if let scenicSpotId {
query.append(URLQueryItem(name: "scenic_spot_id", value: String(scenicSpotId)))
}
do {
return try await client.send(
APIRequest(method: .get, path: "/api/app/scenic-queue/setting", queryItems: query)
)
} catch APIError.emptyData {
return ScenicQueueSettingData()
}
}
///
func scenicQueueSaveSetting(_ request: ScenicQueueSaveSettingRequest) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/scenic-queue/save-setting", body: request)
)
}
///
func scenicQueueShootQueueQRCode(scenicId: Int, scenicSpotId: Int) async throws -> ScenicQueueShootQueueQRCodeData {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/scenic-queue/shoot-queue-qrcode",
queryItems: [
URLQueryItem(name: "scenic_id", value: String(scenicId)),
URLQueryItem(name: "scenic_spot_id", value: String(scenicSpotId))
]
)
)
}
///
func scenicQueueSettingChangeLog(
scenicId: Int,
scenicSpotId: Int?,
page: Int = 1,
pageSize: Int = 20
) async throws -> ScenicQueueSettingChangeLogData {
var query = [
URLQueryItem(name: "scenic_id", value: String(scenicId)),
URLQueryItem(name: "page", value: String(max(page, 1))),
URLQueryItem(name: "page_size", value: String(max(pageSize, 1)))
]
if let scenicSpotId {
query.append(URLQueryItem(name: "scenic_spot_id", value: String(scenicSpotId)))
}
do {
return try await client.send(
APIRequest(method: .get, path: "/api/app/scenic-queue/setting-change-log", queryItems: query)
)
} catch APIError.emptyData {
return ScenicQueueSettingChangeLogData()
}
}
}
extension ScenicQueueAPI: ScenicQueueServing {}