Files
suixinkan_uikit/suixinkan/Features/WildPhotographerReport/API/WildPhotographerReportAPI.swift

259 lines
8.2 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.

//
// WildPhotographerReportAPI.swift
// suixinkan
//
import Foundation
///
@MainActor
protocol WildPhotographerReportServing {
///
func reportTypes() async throws -> WildReportTypeListResponse
///
func reportCopy() async throws -> WildReportCopyResponse
///
func submitReport(_ request: WildReportSubmitRequest) async throws -> WildReportSubmitResponse
///
func supplementReport(_ request: WildReportSupplementRequest) async throws
///
func riskMap(_ request: WildReportRiskMapRequest) async throws -> WildReportRiskMapResponse
///
func markerDetail(_ request: WildReportMarkerDetailRequest) async throws -> WildReportMarkerDetailResponse
///
func reportList(_ request: WildReportListRequest) async throws -> WildReportListResponse
///
func reportDetail(id: Int) async throws -> WildReportDetailData
///
func reportShare(id: String) async throws -> WildReportMiniProgramShareData
}
/// 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 reportCopy() async throws -> WildReportCopyResponse {
try await client.send(
APIRequest(method: .get, path: "/api/yf-handset-app/photog/report/copy")
)
}
///
func submitReport(_ request: WildReportSubmitRequest) async throws -> WildReportSubmitResponse {
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 riskMap(_ request: WildReportRiskMapRequest) async throws -> WildReportRiskMapResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/report/risk-map",
queryItems: request.queryItems
)
)
}
///
func markerDetail(_ request: WildReportMarkerDetailRequest) async throws -> WildReportMarkerDetailResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/report/marker-detail",
queryItems: request.queryItems
)
)
}
///
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))]
)
)
}
///
func reportShare(id: String) async throws -> WildReportMiniProgramShareData {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/report/share",
queryItems: [URLQueryItem(name: "id", value: id)]
)
)
}
}
///
struct WildReportSupplementRequest: Encodable, Equatable {
let id: Int
let desc: String?
let evidences: [WildReportEvidenceRequest]?
}
///
struct WildReportRiskMapRequest: Encodable, Equatable {
let scenicId: Int
let latitude: Double?
let longitude: Double?
var queryItems: [URLQueryItem] {
var items = [URLQueryItem(name: "scenic_id", value: String(scenicId))]
if let latitude {
items.append(URLQueryItem(name: "latitude", value: String(latitude)))
}
if let longitude {
items.append(URLQueryItem(name: "longitude", value: String(longitude)))
}
return items
}
enum CodingKeys: String, CodingKey {
case scenicId = "scenic_id"
case latitude
case longitude
}
}
///
struct WildReportMarkerDetailRequest: Encodable, Equatable {
let scenicId: Int
let markerType: String
let id: Int
let latitude: Double?
let longitude: Double?
var queryItems: [URLQueryItem] {
var items = [
URLQueryItem(name: "scenic_id", value: String(scenicId)),
URLQueryItem(name: "marker_type", value: markerType),
URLQueryItem(name: "id", value: String(id))
]
if let latitude {
items.append(URLQueryItem(name: "latitude", value: String(latitude)))
}
if let longitude {
items.append(URLQueryItem(name: "longitude", value: String(longitude)))
}
return items
}
enum CodingKeys: String, CodingKey {
case scenicId = "scenic_id"
case markerType = "marker_type"
case id
case latitude
case longitude
}
}
///
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"
}
}
/// ID
struct WildReportSubmitResponse: Decodable, Equatable {
let id: Int
let complaintNo: String
enum CodingKeys: String, CodingKey {
case id
case complaintNo = "complaint_no"
}
init(id: Int = 0, complaintNo: String = "") {
self.id = id
self.complaintNo = complaintNo
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(Int.self, forKey: .id) ?? 0
complaintNo = try container.decodeIfPresent(String.self, forKey: .complaintNo) ?? ""
}
}
///
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"
}
}