133 lines
4.0 KiB
Swift
133 lines
4.0 KiB
Swift
//
|
||
// WildPhotographerReportAPI.swift
|
||
// suixinkan
|
||
//
|
||
|
||
import Foundation
|
||
|
||
/// 举报摄影师服务协议,封装举报类型等后端接口。
|
||
@MainActor
|
||
protocol WildPhotographerReportServing {
|
||
/// 拉取提交举报可选类型。
|
||
func reportTypes() async throws -> WildReportTypeListResponse
|
||
/// 提交摄影师举报。
|
||
func submitReport(_ request: WildReportSubmitRequest) async throws
|
||
/// 为已有举报补充证据。
|
||
func supplementReport(_ request: WildReportSupplementRequest) async throws
|
||
/// 拉取我的举报列表。
|
||
func reportList(_ request: WildReportListRequest) async throws -> WildReportListResponse
|
||
/// 拉取单条举报详情。
|
||
func reportDetail(id: Int) async throws -> WildReportDetailData
|
||
}
|
||
|
||
/// 举报摄影师 API,负责和 `photog/report` 相关接口通讯。
|
||
@MainActor
|
||
final class WildPhotographerReportAPI: WildPhotographerReportServing {
|
||
private let client: APIClient
|
||
|
||
/// 初始化举报摄影师 API。
|
||
init(client: APIClient) {
|
||
self.client = client
|
||
}
|
||
|
||
/// 拉取提交举报可选类型。
|
||
func reportTypes() async throws -> WildReportTypeListResponse {
|
||
try await client.send(
|
||
APIRequest(method: .get, path: "/api/yf-handset-app/photog/report/types")
|
||
)
|
||
}
|
||
|
||
/// 提交摄影师举报。
|
||
func submitReport(_ request: WildReportSubmitRequest) async throws {
|
||
let _: EmptyPayload = try await client.send(
|
||
APIRequest(
|
||
method: .post,
|
||
path: "/api/yf-handset-app/photog/report/submit",
|
||
body: request
|
||
)
|
||
)
|
||
}
|
||
|
||
/// 为已有举报补充证据。
|
||
func supplementReport(_ request: WildReportSupplementRequest) async throws {
|
||
let _: EmptyPayload = try await client.send(
|
||
APIRequest(
|
||
method: .post,
|
||
path: "/api/yf-handset-app/photog/report/supplement",
|
||
body: request
|
||
)
|
||
)
|
||
}
|
||
|
||
/// 拉取我的举报列表。
|
||
func reportList(_ request: WildReportListRequest) async throws -> WildReportListResponse {
|
||
try await client.send(
|
||
APIRequest(
|
||
method: .get,
|
||
path: "/api/yf-handset-app/photog/report/list",
|
||
queryItems: request.queryItems
|
||
)
|
||
)
|
||
}
|
||
|
||
/// 拉取单条举报详情。
|
||
func reportDetail(id: Int) async throws -> WildReportDetailData {
|
||
try await client.send(
|
||
APIRequest(
|
||
method: .get,
|
||
path: "/api/yf-handset-app/photog/report/detail",
|
||
queryItems: [URLQueryItem(name: "id", value: String(id))]
|
||
)
|
||
)
|
||
}
|
||
}
|
||
|
||
/// 补充证据接口请求体。
|
||
struct WildReportSupplementRequest: Encodable, Equatable {
|
||
let id: Int
|
||
let desc: String?
|
||
let evidences: [WildReportEvidenceRequest]?
|
||
}
|
||
|
||
/// 提交举报接口请求体。
|
||
struct WildReportSubmitRequest: Encodable, Equatable {
|
||
let scenicId: Int
|
||
let reportType: Int
|
||
let desc: String
|
||
let storeUserId: Int?
|
||
let contactPhone: String?
|
||
let locationName: String?
|
||
let locationAddress: String?
|
||
let lat: Double
|
||
let lng: Double
|
||
let evidences: [WildReportEvidenceRequest]
|
||
let paymentScreenshots: [WildReportEvidenceRequest]
|
||
|
||
enum CodingKeys: String, CodingKey {
|
||
case scenicId = "scenic_id"
|
||
case reportType = "report_type"
|
||
case desc
|
||
case storeUserId = "store_user_id"
|
||
case contactPhone = "contact_phone"
|
||
case locationName = "location_name"
|
||
case locationAddress = "location_address"
|
||
case lat
|
||
case lng
|
||
case evidences
|
||
case paymentScreenshots = "payment_screenshots"
|
||
}
|
||
}
|
||
|
||
/// 提交举报接口中的附件项。
|
||
struct WildReportEvidenceRequest: Encodable, Equatable {
|
||
let fileURL: String
|
||
let fileType: Int
|
||
let fileName: String?
|
||
|
||
enum CodingKeys: String, CodingKey {
|
||
case fileURL = "file_url"
|
||
case fileType = "file_type"
|
||
case fileName = "file_name"
|
||
}
|
||
}
|