jsdw_ios/QuickLocation/API/GroupAPI.swift

82 lines
2.4 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: create、dismiss、setdefault
/// - requestData:[String: Any] 根据操作传入对应的值
case operate(opType: String, requestData: [String: Any])
/// 提醒对方开启权限
case privilegeRemind(title: String, content: String, groupKey: String, userId: String)
}
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"
case .privilegeRemind:
return "mapi/group/privilege/remind"
}
}
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())
case let .privilegeRemind(title, content, groupKey, userId):
var params = Parameters()
params["title"] = title
params["content"] = content
params["group_key"] = groupKey
params["user_id"] = userId
return .requestParameters(parameters: params, encoding: JSONEncoding())
}
}
}