Files

142 lines
4.2 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.

//
// StatisticsAPI.swift
// suixinkan
//
import Foundation
@MainActor
/// API//
final class StatisticsAPI {
private let client: APIClient
private let pageSize = 15
init(client: APIClient) {
self.client = client
}
///
func photographerSummary(scenicId: Int, range: String) async throws -> StatisticsSummaryResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/analyse/user",
queryItems: [
URLQueryItem(name: "scenic_id", value: String(scenicId)),
URLQueryItem(name: "range", value: range),
]
)
)
}
///
func photographerDaily(
scenicId: Int,
startTime: String,
endTime: String,
page: Int
) async throws -> ListDataResponse<StatisticsDailyItem> {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/analyse/user/daily",
queryItems: dailyQueryItems(
idName: "scenic_id",
idValue: scenicId,
startTime: startTime,
endTime: endTime,
page: page
)
)
)
}
///
func scenicAdminSummary(scenicId: Int, range: String) async throws -> StatisticsSummaryResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/scenic-admin/analyse",
queryItems: [
URLQueryItem(name: "scenic_id", value: String(scenicId)),
URLQueryItem(name: "range", value: range),
]
)
)
}
///
func scenicAdminDaily(
scenicId: Int,
startTime: String,
endTime: String,
page: Int
) async throws -> ListDataResponse<StatisticsDailyItem> {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/scenic-admin/analyse/daily",
queryItems: dailyQueryItems(
idName: "scenic_id",
idValue: scenicId,
startTime: startTime,
endTime: endTime,
page: page
)
)
)
}
///
func storeSummary(storeId: Int, range: String) async throws -> StatisticsSummaryResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/store/analyse",
queryItems: [
URLQueryItem(name: "store_id", value: String(storeId)),
URLQueryItem(name: "range", value: range),
]
)
)
}
///
func storeDaily(
storeId: Int,
startTime: String,
endTime: String,
page: Int
) async throws -> ListDataResponse<StatisticsDailyItem> {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/store/analyse/daily",
queryItems: dailyQueryItems(
idName: "store_id",
idValue: storeId,
startTime: startTime,
endTime: endTime,
page: page
)
)
)
}
private func dailyQueryItems(
idName: String,
idValue: Int,
startTime: String,
endTime: String,
page: Int
) -> [URLQueryItem] {
[
URLQueryItem(name: idName, value: String(idValue)),
URLQueryItem(name: "start_time", value: startTime),
URLQueryItem(name: "end_time", value: endTime),
URLQueryItem(name: "page", value: String(page)),
URLQueryItem(name: "paeg_size", value: String(pageSize)),
]
}
}