Files
suixinkan_uikit/suixinkan/Features/PunchPoint/API/PunchPointAPI.swift

85 lines
2.8 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.

//
// PunchPointAPI.swift
// suixinkan
//
import Foundation
/// API 便 ViewModel
@MainActor
protocol PunchPointAPIProtocol {
///
func list(scenicAreaId: String, status: Int, page: Int, pageSize: Int) async throws -> PunchPointListResponse
///
func info(id: Int64) async throws -> PunchPointDetail
///
func add(_ request: PunchPointSaveRequest) async throws
///
func edit(_ request: PunchPointSaveRequest) async throws
///
func delete(id: Int64) async throws
}
/// API Android `NetworkApi` `photog/scenic-spot`
@MainActor
final class PunchPointAPI: PunchPointAPIProtocol {
private let client: APIClient
/// API
init(client: APIClient) {
self.client = client
}
///
func list(scenicAreaId: String, status: Int, page: Int, pageSize: Int) async throws -> PunchPointListResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/scenic-spot/list",
queryItems: [
URLQueryItem(name: "scenic_area_id", value: scenicAreaId),
URLQueryItem(name: "status", value: String(status)),
URLQueryItem(name: "page", value: String(max(page, 1))),
URLQueryItem(name: "page_size", value: String(max(pageSize, 1))),
]
)
)
}
///
func info(id: Int64) async throws -> PunchPointDetail {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/scenic-spot/info",
queryItems: [URLQueryItem(name: "id", value: String(id))]
)
)
}
///
func add(_ request: PunchPointSaveRequest) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/yf-handset-app/photog/scenic-spot/add", body: request)
)
}
///
func edit(_ request: PunchPointSaveRequest) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/yf-handset-app/photog/scenic-spot/edit", body: request)
)
}
///
func delete(id: Int64) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/yf-handset-app/photog/scenic-spot/delete",
body: PunchPointIDRequest(id: id)
)
)
}
}