Files
suixinkan_uikit/suixinkan/Features/MaterialManagement/API/MaterialManagementAPI.swift

141 lines
4.7 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.

//
// MaterialManagementAPI.swift
// suixinkan
//
import Foundation
///
@MainActor
protocol MaterialManagementServing {
///
func list(status: Int, keyword: String?, page: Int, pageSize: Int) async throws -> MaterialListResponse
///
func detail(id: Int) async throws -> MaterialDetail
///
func setListingStatus(id: Int, listingStatus: Int) async throws
///
func delete(id: Int) async throws
///
func addTag(name: String) async throws -> Int
///
func upload(_ request: MaterialUploadRequest) async throws
///
func edit(_ request: MaterialUploadRequest) async throws
///
func scenicSpotListAll(scenicId: String) async throws -> ScenicSpotListResponse
}
/// API Android `NetworkApi` `media-album type=1`
@MainActor
final class MaterialManagementAPI: MaterialManagementServing {
private let client: APIClient
/// API
init(client: APIClient) {
self.client = client
}
/// `type=1`
func list(status: Int, keyword: String?, page: Int = 1, pageSize: Int = 10) async throws -> MaterialListResponse {
var items = [
URLQueryItem(name: "status", value: String(status)),
URLQueryItem(name: "type", value: "1"),
URLQueryItem(name: "page", value: String(max(page, 1))),
URLQueryItem(name: "page_size", value: String(max(pageSize, 1))),
]
if let keyword = keyword?.trimmingCharacters(in: .whitespacesAndNewlines), !keyword.isEmpty {
items.append(URLQueryItem(name: "keyword", value: keyword))
}
return try await client.send(
APIRequest(method: .get, path: "/api/app/media-album/list", queryItems: items)
)
}
/// `type=1`
func detail(id: Int) async throws -> MaterialDetail {
try await client.send(
APIRequest(
method: .get,
path: "/api/app/media-album/detail",
queryItems: [
URLQueryItem(name: "id", value: String(id)),
URLQueryItem(name: "type", value: "1"),
]
)
)
}
/// `type=1`
func setListingStatus(id: Int, listingStatus: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/app/media-album/operation",
queryItems: [
URLQueryItem(name: "id", value: String(id)),
URLQueryItem(name: "listing_status", value: String(listingStatus)),
URLQueryItem(name: "type", value: "1"),
]
)
)
}
/// `type=1`
func delete(id: Int) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/app/media-album/delete",
queryItems: [
URLQueryItem(name: "id", value: String(id)),
URLQueryItem(name: "type", value: "1"),
]
)
)
}
///
func addTag(name: String) async throws -> Int {
try await client.send(
APIRequest(
method: .post,
path: "/api/app/media-album/add-tag",
queryItems: [URLQueryItem(name: "name", value: name)]
)
)
}
///
func upload(_ request: MaterialUploadRequest) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/media-album/upload", body: request)
)
}
///
func edit(_ request: MaterialUploadRequest) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(method: .post, path: "/api/app/media-album/edit", body: request)
)
}
///
func scenicSpotListAll(scenicId: String) async throws -> ScenicSpotListResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/scenic-spot/list-all",
queryItems: [URLQueryItem(name: "scenic_id", value: scenicId)]
)
)
}
}