Files
suixinkan_ios_new/suixinkan/Features/LocationReport/API/LocationReportAPI.swift
汉秋 0d4b63d273 Add PunchPoint and LocationReport modules with home routing.
Migrate check-in point management and location reporting from placeholders to full MVVM flows, including foreground location support and unit tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:08:41 +08:00

83 lines
3.0 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.

//
// LocationReportAPI.swift
// suixinkan
//
// Created by Codex on 2026/6/24.
//
import Foundation
import Observation
/// 便 ViewModel
@MainActor
protocol LocationReportServing {
///
func reportLocation(staffId: Int, latitude: Double, longitude: Double, address: String, type: LocationReportType, scenicId: Int) async throws -> LocationReportSubmitResponse
///
func locationReportList(staffId: Int, page: Int, pageSize: Int, type: LocationReportType, startDate: String?, endDate: String?) async throws -> ListPayload<LocationReportHistoryItem>
}
/// API
@MainActor
@Observable
final class LocationReportAPI: LocationReportServing {
@ObservationIgnored private let client: APIClient
/// API
init(client: APIClient) {
self.client = client
}
///
func reportLocation(
staffId: Int,
latitude: Double,
longitude: Double,
address: String,
type: LocationReportType,
scenicId: Int
) async throws -> LocationReportSubmitResponse {
try await client.send(
APIRequest(
method: .post,
path: "/api/yf-handset-app/photog/loacation/report",
queryItems: [
URLQueryItem(name: "staff_id", value: "\(staffId)"),
URLQueryItem(name: "latitude", value: "\(latitude)"),
URLQueryItem(name: "longitude", value: "\(longitude)"),
URLQueryItem(name: "address", value: address),
URLQueryItem(name: "type", value: "\(type.rawValue)"),
URLQueryItem(name: "scenic_id", value: "\(scenicId)")
]
)
)
}
///
func locationReportList(
staffId: Int,
page: Int = 1,
pageSize: Int = 20,
type: LocationReportType = .all,
startDate: String? = nil,
endDate: String? = nil
) async throws -> ListPayload<LocationReportHistoryItem> {
var query = [
URLQueryItem(name: "staff_id", value: "\(staffId)"),
URLQueryItem(name: "page", value: "\(max(page, 1))"),
URLQueryItem(name: "page_size", value: "\(max(pageSize, 1))"),
URLQueryItem(name: "type", value: "\(max(type.rawValue, 0))")
]
if let startDate, !startDate.isEmpty {
query.append(URLQueryItem(name: "start_date", value: startDate))
}
if let endDate, !endDate.isEmpty {
query.append(URLQueryItem(name: "end_date", value: endDate))
}
return try await client.send(
APIRequest(method: .get, path: "/api/yf-handset-app/photog/loacation/list", queryItems: query)
)
}
}