// // 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?) } 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: return "/creator-community/comment" } } var method: Moya.Method { switch self { case .createCommunityPost, .communityPostLike, .createCommunityPostComment: return .post case .getCommunityPostList: return .get } } 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) } } var headers: [String : String]? { return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"] } }