sodalive-ios/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityApi.swift

105 lines
3.6 KiB
Swift

//
// CreatorCommunityApi.swift
// SodaLive
//
// Created by klaus on 2023/12/19.
//
import Foundation
import Moya
enum CreatorCommunityApi {
case createCommunityPost(parameters: [MultipartFormData])
case getCommunityPostList(creatorId: Int, page: Int, size: Int)
case communityPostLike(postId: Int)
case createCommunityPostComment(comment: String, postId: Int, parentId: Int?)
case getCommunityPostCommentList(postId: Int, page: Int, size: Int)
case getCommentReplyList(commentId: Int, page: Int, size: Int)
case modifyComment(request: ModifyCommunityPostCommentRequest)
}
extension CreatorCommunityApi: TargetType {
var baseURL: URL {
return URL(string: BASE_URL)!
}
var path: String {
switch self {
case .createCommunityPost, .getCommunityPostList:
return "/creator-community"
case .communityPostLike:
return "/creator-community/like"
case .createCommunityPostComment, .modifyComment:
return "/creator-community/comment"
case .getCommunityPostCommentList(let postId, _, _):
return "/creator-community/\(postId)/comment"
case .getCommentReplyList(let commentId, _, _):
return "/creator-community/comment/\(commentId)"
}
}
var method: Moya.Method {
switch self {
case .createCommunityPost, .communityPostLike, .createCommunityPostComment:
return .post
case .getCommunityPostList, .getCommunityPostCommentList, .getCommentReplyList:
return .get
case .modifyComment:
return .put
}
}
var task: Moya.Task {
switch self {
case .createCommunityPost(let parameters):
return .uploadMultipart(parameters)
case .getCommunityPostList(let creatorId, let page, let size):
let parameters = [
"creatorId": creatorId,
"page": page - 1,
"size": size,
"timezone": TimeZone.current.identifier
] as [String: Any]
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
case .communityPostLike(let postId):
let request = PostCommunityPostLikeRequest(postId: postId)
return .requestJSONEncodable(request)
case .createCommunityPostComment(let comment, let postId, let parentId):
let request = CreateCommunityPostCommentRequest(comment: comment, postId: postId, parentId: parentId)
return .requestJSONEncodable(request)
case .getCommunityPostCommentList(_, let page, let size):
let parameters = [
"page": page - 1,
"size": size,
"timezone": TimeZone.current.identifier
] as [String: Any]
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
case .getCommentReplyList(_, let page, let size):
let parameters = [
"page": page - 1,
"size": size,
"timezone": TimeZone.current.identifier
] as [String: Any]
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
case .modifyComment(let request):
return .requestJSONEncodable(request)
}
}
var headers: [String : String]? {
return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"]
}
}