Files
suixinkan_ios_uikit/suixinkan_ios/Features/Statistics/API/StatisticsAPI.swift
2026-06-26 14:33:31 +08:00

81 lines
2.5 KiB
Swift
Raw 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.

//
// StatisticsAPI.swift
// suixinkan
//
// Created by Codex on 2026/6/22.
//
import Foundation
@MainActor
/// 便
protocol StatisticsServing {
///
func summary(scenicId: Int, range: String, isScenicAdmin: Bool) async throws -> StatisticsSummaryResponse
///
func dailyList(
scenicId: Int,
startTime: String,
endTime: String,
page: Int,
pageSize: Int,
isScenicAdmin: Bool
) async throws -> DataListPayload<StatisticsDailyItem>
}
@MainActor
/// API
final class StatisticsAPI: StatisticsServing {
private let client: APIClient
/// API
init(client: APIClient) {
self.client = client
}
///
func summary(scenicId: Int, range: String, isScenicAdmin: Bool) async throws -> StatisticsSummaryResponse {
try await client.send(
APIRequest(
method: .get,
path: isScenicAdmin ? "/api/app/scenic-admin/analyse" : "/api/yf-handset-app/photog/analyse/user",
queryItems: [
URLQueryItem(name: "scenic_id", value: "\(scenicId)"),
URLQueryItem(name: "range", value: range)
]
)
)
}
///
func dailyList(
scenicId: Int,
startTime: String,
endTime: String,
page: Int = 1,
pageSize: Int = 15,
isScenicAdmin: Bool
) async throws -> DataListPayload<StatisticsDailyItem> {
var query = [
URLQueryItem(name: "scenic_id", value: "\(scenicId)"),
URLQueryItem(name: "page", value: "\(max(page, 1))"),
URLQueryItem(name: "page_size", value: "\(max(pageSize, 1))")
]
if !startTime.isEmpty {
query.append(URLQueryItem(name: "start_time", value: startTime))
}
if !endTime.isEmpty {
query.append(URLQueryItem(name: "end_time", value: endTime))
}
return try await client.send(
APIRequest(
method: .get,
path: isScenicAdmin ? "/api/app/scenic-admin/analyse/daily" : "/api/yf-handset-app/photog/analyse/user/daily",
queryItems: query
)
)
}
}