jsdw_ios/QuickLocation/API/GroupAPI.swift

70 lines
1.8 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.

//
// GroupAPI.swift
// QuickLocation
//
// Created by on 2026/6/1.
//
import Moya
import SwiftyUserDefaults
internal import Alamofire
/// API
enum GroupAPI {
///
case groupInfo
///
case groupTemplates
///
case groupUsers(groupKey: String)
///
/// - Parameters:
/// - opType: createdismisssetdefault
/// - requestData[String: Any]
case operate(opType: String, requestData: [String: Any])
}
extension GroupAPI: MultiTargetProtocol {
var path: String {
switch self {
case .groupInfo:
return "mapi/user/fullinfo"
case .groupTemplates:
return "mapi/group/template"
case .groupUsers:
return "mapi/group/users"
case .operate:
return "mapi/group/operate"
}
}
var method: Moya.Method {
switch self {
case .groupInfo, .groupTemplates, .groupUsers:
return .get
default:
return .post
}
}
var task: Moya.Task {
switch self {
case .groupInfo:
return .requestParameters(parameters: Parameters(), encoding: URLEncoding())
case .groupTemplates:
return .requestPlain
case let .groupUsers(groupKey):
return .requestParameters(parameters: ["group_key": groupKey], encoding: URLEncoding())
case let .operate(opType, requestData):
var params = Parameters()
params["op_type"] = opType
params.merge(requestData) { _, new in new }
return .requestParameters(parameters: params, encoding: JSONEncoding())
}
}
}