|
@@ -0,0 +1,385 @@
|
|
|
+//
|
|
|
+// SwiftMoyaServiceCommunityApi.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by 南鑫林 on 2019/6/24.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+import Foundation
|
|
|
+import Moya
|
|
|
+
|
|
|
+// MARK: - 话题组列表
|
|
|
+/// 话题组列表
|
|
|
+public let kCommunityTopicCategoryApi = "/community/topicCategory"
|
|
|
+
|
|
|
+// MARK: - 关注推荐话题
|
|
|
+/// 关注推荐话题
|
|
|
+public let kCommunityMemberFollowTopicApi = "/community/memberFollowTopic"
|
|
|
+
|
|
|
+// MARK: - 个人中心内容
|
|
|
+/// 个人中心内容
|
|
|
+public let kCommunityPostMyApi = "/community/post/my"
|
|
|
+
|
|
|
+// MARK: - 话题列表
|
|
|
+/// 话题列表
|
|
|
+public let kCommunityTopicsApi = "/community/topic"
|
|
|
+
|
|
|
+// MARK: - 内容列表
|
|
|
+/// 内容列表(Get)
|
|
|
+public let kCommunityPostsApi = "/community/post"
|
|
|
+
|
|
|
+// MARK: - 发布内容
|
|
|
+/// 发布内容(Post)
|
|
|
+public let kCommunityPublishApi = "/community/post"
|
|
|
+
|
|
|
+// MARK: - 删除内容
|
|
|
+/// 删除内容(Post)
|
|
|
+public let kCommunityDeleteApi = "/community/post"
|
|
|
+
|
|
|
+// MARK: - 获取上传地址和凭证
|
|
|
+/// 获取上传地址和凭证(视频)
|
|
|
+public let kCommunityVideoUploadAuthApi = "/community/getVodUploadAuth"
|
|
|
+
|
|
|
+/// 获取上传地址和凭证(图片)
|
|
|
+public let kCommunityImageUploadAuthApi = "/community/vod/upload/image"
|
|
|
+
|
|
|
+// MARK: - 视频列表
|
|
|
+/// 视频列表
|
|
|
+public let kCommunityVideoListApi = "/community/post/video"
|
|
|
+
|
|
|
+// MARK: - 关注页面feed流
|
|
|
+/// 关注页面feed流
|
|
|
+public let kCommunityFollowFeedApi = "/community/feed"
|
|
|
+
|
|
|
+// MARK: - 推荐内容
|
|
|
+/// 推荐内容
|
|
|
+public let kCommunityPostSuggestApi = "/community/post/suggest"
|
|
|
+
|
|
|
+// MARK: - 话题详情
|
|
|
+/// 话题详情
|
|
|
+public let kCommunityTopicDetailApi = "/community/topic/detail"
|
|
|
+
|
|
|
+// MARK: - 话题内容列表
|
|
|
+/// 话题内容列表
|
|
|
+public let kCommunityPostTopicApi = "/community/post/topic"
|
|
|
+
|
|
|
+// MARK: - 我关注的话题列表
|
|
|
+/// 我关注的话题列表
|
|
|
+public let kCommunityMemberFollowTopicListApi = "/community/memberFollowTopic"
|
|
|
+
|
|
|
+// MARK: - 关注话题(单个)
|
|
|
+/// 关注话题(单个)
|
|
|
+public let kCommunityMemberFollowTopicFollowApi = "/community/memberFollowTopic/follow"
|
|
|
+
|
|
|
+// MARK: - 取消关注话题
|
|
|
+/// 取消关注话题
|
|
|
+public let kCommunityMemberFollowTopicCancelFollowApi = "/community/memberFollowTopic/cancel"
|
|
|
+
|
|
|
+// MARK: - 内容详情
|
|
|
+/// 内容详情
|
|
|
+public let kCommunityPostDetailApi = "/community/post/detail"
|
|
|
+
|
|
|
+// MARK: - 评论列表
|
|
|
+/// 评论列表
|
|
|
+public let kCommunityPostCommentsApi = "/community/post/comment"
|
|
|
+
|
|
|
+// MARK: - 回复列表
|
|
|
+/// 回复列表
|
|
|
+public let kCommunityPostReplyApi = "/community/post/reply"
|
|
|
+
|
|
|
+//// MARK: - 评论&回复
|
|
|
+///// 评论&回复
|
|
|
+public let kCommunityPostCommentApi = "/community/post/comment"
|
|
|
+
|
|
|
+//// MARK: - 删除评论
|
|
|
+///// 删除评论
|
|
|
+public let kCommunityPostDeleteCommentApi = "/community/post/comment"
|
|
|
+
|
|
|
+//// MARK: - 用户上传音乐
|
|
|
+///// 用户上传音乐
|
|
|
+public let kCommunityUploadMusicApi = "/community/music/upload"
|
|
|
+
|
|
|
+//// MARK: - 热门推荐音乐列表
|
|
|
+///// 热门推荐音乐列表
|
|
|
+public let kCommunityRecMusicListApi = "/community/musicList"
|
|
|
+
|
|
|
+//// MARK: - 获取音乐分类
|
|
|
+///// 获取音乐分类
|
|
|
+public let kCommunityGetMusicCategoryApi = "/community/category/list"
|
|
|
+
|
|
|
+//// MARK: - 获取分类下所有音乐
|
|
|
+///// 获取分类下所有音乐
|
|
|
+public let kCommunityCateMusicListApi = "/community/music"
|
|
|
+
|
|
|
+/// 社区
|
|
|
+///
|
|
|
+/// - communityTopicCategory: 话题组列表
|
|
|
+/// - communityMemberFollowTopic: 关注推荐话题
|
|
|
+/// - communityPostMy: 个人中心内容
|
|
|
+/// - communityTopics: 话题列表
|
|
|
+/// - communityPosts: 内容列表
|
|
|
+/// - communityPublish: 发布内容
|
|
|
+/// - communityVideoUploadAuth: 视频上传凭证
|
|
|
+/// - communityImageUploadAuth: 图片上传凭证
|
|
|
+/// - communityVideoList: 视频列表
|
|
|
+/// - communityFeed: 关注页面feed流
|
|
|
+/// - communityPostSuggest: 关注页面feed流
|
|
|
+/// - communityTopicDetail: 话题详情
|
|
|
+/// - communityPostTopic: 话题内容列表
|
|
|
+/// - communityMemberFollowTopicList: 我关注的话题列表
|
|
|
+/// - communityMemberFollowTopicFollow: 关注话题(单个)
|
|
|
+/// - communityMemberFollowTopicCancelFollow: 取消关注话题
|
|
|
+/// - communityPostDetail: 内容详情
|
|
|
+/// - communityPostComments : 评论列表
|
|
|
+/// - communityPostReply : 回复列表
|
|
|
+/// - communityPostComment : 评论&回复
|
|
|
+/// - communityPostDeleteComment : 删除评论
|
|
|
+/// - communityUploadMusic : 用户上传音乐
|
|
|
+/// - communityRecMusicList : 热门推荐音乐列表
|
|
|
+/// - communityGetMusicCategory : 获取音乐分类
|
|
|
+/// - communityCateMusicList : 获取分类下所有音乐
|
|
|
+
|
|
|
+public enum SwiftMoyaServiceCommunityApi {
|
|
|
+ case communityTopicCategory(parameters:Dictionary<String, Any>)
|
|
|
+ case communityMemberFollowTopic(parameters:Dictionary<String, Any>)
|
|
|
+ case communityPostMy(parameters:Dictionary<String, Any>)
|
|
|
+ case communityTopics(parameters:Dictionary<String, Any>)
|
|
|
+ case communityPosts(parameters:Dictionary<String, Any>)
|
|
|
+ case communityPublish(parameters:Dictionary<String, Any>)
|
|
|
+ case communityDelete(parameters:Dictionary<String, Any>)
|
|
|
+ case communityVideoUploadAuth(parameters:Dictionary<String, Any>)
|
|
|
+ case communityImageUploadAuth(parameters:Dictionary<String, Any>)
|
|
|
+ case communityVideoList(parameters:Dictionary<String, Any>)
|
|
|
+ case communityFollowFeed(parameters:Dictionary<String, Any>)
|
|
|
+ case communityPostSuggest(parameters:Dictionary<String, Any>)
|
|
|
+ case communityTopicDetail(parameters:Dictionary<String, Any>)
|
|
|
+ case communityPostTopic(parameters:Dictionary<String, Any>)
|
|
|
+ case communityMemberFollowTopicList(parameters:Dictionary<String, Any>)
|
|
|
+ case communityMemberFollowTopicFollow(parameters:Dictionary<String, Any>)
|
|
|
+ case communityMemberFollowTopicCancelFollow(parameters:Dictionary<String, Any>)
|
|
|
+ case communityPostDetail(parameters:Dictionary<String, Any>)
|
|
|
+ case communityPostComments(parameters:Dictionary<String, Any>)
|
|
|
+ case communityPostReply(parameters:Dictionary<String, Any>)
|
|
|
+ case communityPostComment(parameters:Dictionary<String, Any>)
|
|
|
+ case communityPostDeleteComment(parameters:Dictionary<String, Any>)
|
|
|
+ case communityUploadMusic(parameters:Dictionary<String, Any>)
|
|
|
+ case communityRecMusicList(parameters:Dictionary<String, Any>)
|
|
|
+ case communityGetMusicCategory(parameters:Dictionary<String, Any>)
|
|
|
+ case communityCateMusicList(parameters:Dictionary<String, Any>)
|
|
|
+}
|
|
|
+
|
|
|
+extension SwiftMoyaServiceCommunityApi: TargetType {
|
|
|
+
|
|
|
+ public var baseURL: URL {
|
|
|
+ switch self {
|
|
|
+ case .communityTopicCategory,
|
|
|
+ .communityMemberFollowTopic,
|
|
|
+ .communityPostMy,
|
|
|
+ .communityTopics,
|
|
|
+ .communityPosts,
|
|
|
+ .communityPublish,
|
|
|
+ .communityDelete,
|
|
|
+ .communityVideoUploadAuth,
|
|
|
+ .communityImageUploadAuth,
|
|
|
+ .communityVideoList,
|
|
|
+ .communityFollowFeed,
|
|
|
+ .communityPostSuggest,
|
|
|
+ .communityTopicDetail,
|
|
|
+ .communityPostTopic,
|
|
|
+ .communityMemberFollowTopicList,
|
|
|
+ .communityMemberFollowTopicFollow,
|
|
|
+ .communityMemberFollowTopicCancelFollow,
|
|
|
+ .communityPostDetail,
|
|
|
+ .communityPostComments,
|
|
|
+ .communityPostReply,
|
|
|
+ .communityPostComment,
|
|
|
+ .communityPostDeleteComment,
|
|
|
+ .communityUploadMusic,
|
|
|
+ .communityRecMusicList,
|
|
|
+ .communityGetMusicCategory,
|
|
|
+ .communityCateMusicList
|
|
|
+ :
|
|
|
+ return URL(string: kApiDataPrefix())!
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public var path: String {
|
|
|
+ switch self {
|
|
|
+ case .communityTopicCategory:
|
|
|
+ return kCommunityTopicCategoryApi
|
|
|
+ case .communityMemberFollowTopic:
|
|
|
+ return kCommunityMemberFollowTopicApi
|
|
|
+ case .communityPostMy:
|
|
|
+ return kCommunityPostMyApi
|
|
|
+ case .communityTopics:
|
|
|
+ return kCommunityTopicsApi
|
|
|
+ case .communityPosts:
|
|
|
+ return kCommunityPostsApi
|
|
|
+ case .communityPublish:
|
|
|
+ return kCommunityPublishApi
|
|
|
+ case .communityDelete:
|
|
|
+ return kCommunityDeleteApi
|
|
|
+ case .communityVideoUploadAuth:
|
|
|
+ return kCommunityVideoUploadAuthApi
|
|
|
+ case .communityImageUploadAuth:
|
|
|
+ return kCommunityImageUploadAuthApi
|
|
|
+ case .communityVideoList:
|
|
|
+ return kCommunityVideoListApi
|
|
|
+ case .communityFollowFeed:
|
|
|
+ return kCommunityFollowFeedApi
|
|
|
+ case .communityPostSuggest:
|
|
|
+ return kCommunityPostSuggestApi
|
|
|
+ case .communityTopicDetail:
|
|
|
+ return kCommunityTopicDetailApi
|
|
|
+ case .communityPostTopic:
|
|
|
+ return kCommunityPostTopicApi
|
|
|
+ case .communityMemberFollowTopicList:
|
|
|
+ return kCommunityMemberFollowTopicListApi
|
|
|
+ case .communityMemberFollowTopicFollow:
|
|
|
+ return kCommunityMemberFollowTopicFollowApi
|
|
|
+ case .communityMemberFollowTopicCancelFollow:
|
|
|
+ return kCommunityMemberFollowTopicCancelFollowApi
|
|
|
+ case .communityPostDetail:
|
|
|
+ return kCommunityPostDetailApi
|
|
|
+ case .communityPostComments:
|
|
|
+ return kCommunityPostCommentsApi
|
|
|
+ case .communityPostReply:
|
|
|
+ return kCommunityPostReplyApi
|
|
|
+ case .communityPostComment:
|
|
|
+ return kCommunityPostCommentApi
|
|
|
+ case .communityPostDeleteComment:
|
|
|
+ return kCommunityPostDeleteCommentApi
|
|
|
+ case .communityUploadMusic:
|
|
|
+ return kCommunityUploadMusicApi
|
|
|
+ case .communityRecMusicList:
|
|
|
+ return kCommunityRecMusicListApi
|
|
|
+ case .communityGetMusicCategory:
|
|
|
+ return kCommunityGetMusicCategoryApi
|
|
|
+ case .communityCateMusicList:
|
|
|
+ return kCommunityCateMusicListApi
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public var method: Moya.Method {
|
|
|
+ switch self {
|
|
|
+ case .communityMemberFollowTopic,
|
|
|
+ .communityPublish,
|
|
|
+ .communityMemberFollowTopicFollow,
|
|
|
+ .communityPostComment,
|
|
|
+ .communityUploadMusic
|
|
|
+ :
|
|
|
+ return .post
|
|
|
+ case .communityTopicCategory,
|
|
|
+ .communityPostMy,
|
|
|
+ .communityTopics,
|
|
|
+ .communityPosts,
|
|
|
+ .communityVideoUploadAuth,
|
|
|
+ .communityImageUploadAuth,
|
|
|
+ .communityVideoList,
|
|
|
+ .communityFollowFeed,
|
|
|
+ .communityPostSuggest,
|
|
|
+ .communityTopicDetail,
|
|
|
+ .communityPostTopic,
|
|
|
+ .communityMemberFollowTopicList,
|
|
|
+ .communityPostDetail,
|
|
|
+ .communityPostComments,
|
|
|
+ .communityPostReply,
|
|
|
+ .communityRecMusicList,
|
|
|
+ .communityGetMusicCategory,
|
|
|
+ .communityCateMusicList
|
|
|
+ :
|
|
|
+ return .get
|
|
|
+ case .communityMemberFollowTopicCancelFollow,
|
|
|
+ .communityDelete,
|
|
|
+ .communityPostDeleteComment
|
|
|
+ :
|
|
|
+ return .delete
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - 请求任务事件(这里附带上参数)
|
|
|
+ public var task: Task {
|
|
|
+ switch self {
|
|
|
+ case .communityTopicCategory(var parameters),
|
|
|
+ .communityMemberFollowTopic(var parameters),
|
|
|
+ .communityPostMy(var parameters),
|
|
|
+ .communityTopics(var parameters),
|
|
|
+ .communityPosts(var parameters),
|
|
|
+ .communityPublish(var parameters),
|
|
|
+ .communityDelete(var parameters),
|
|
|
+ .communityVideoUploadAuth(var parameters),
|
|
|
+ .communityImageUploadAuth(var parameters),
|
|
|
+ .communityVideoList(var parameters),
|
|
|
+ .communityFollowFeed(var parameters),
|
|
|
+ .communityPostSuggest(var parameters),
|
|
|
+ .communityTopicDetail(var parameters),
|
|
|
+ .communityPostTopic(var parameters),
|
|
|
+ .communityMemberFollowTopicList(var parameters),
|
|
|
+ .communityMemberFollowTopicFollow(var parameters),
|
|
|
+ .communityMemberFollowTopicCancelFollow(var parameters),
|
|
|
+ .communityPostDetail(var parameters),
|
|
|
+ .communityPostComments(var parameters),
|
|
|
+ .communityPostReply(var parameters),
|
|
|
+ .communityPostComment(var parameters),
|
|
|
+ .communityPostDeleteComment(var parameters),
|
|
|
+ .communityUploadMusic(var parameters),
|
|
|
+ .communityRecMusicList(var parameters),
|
|
|
+ .communityGetMusicCategory(var parameters),
|
|
|
+ .communityCateMusicList(var parameters)
|
|
|
+ :
|
|
|
+ let sign = SwiftSign.shared().sign(signType:.AccessToken, parameters: parameters)
|
|
|
+ parameters.updateValue(sign, forKey: "sign")
|
|
|
+ return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // MARK: - 是否执行Alamofire验证
|
|
|
+ public var validate: Bool {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - 这个就是做单元测试模拟的数据,只会在单元测试文件中有作用
|
|
|
+ public var sampleData: Data {
|
|
|
+ return "{}".data(using: String.Encoding.utf8)!
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - 请求头
|
|
|
+ public var headers: [String : String]? {
|
|
|
+ //同task,具体选择看后台 有application/x-www-form-urlencoded 、application/json
|
|
|
+ switch self {
|
|
|
+ case .communityTopicCategory,
|
|
|
+ .communityMemberFollowTopic,
|
|
|
+ .communityPostMy,
|
|
|
+ .communityTopics,
|
|
|
+ .communityPosts,
|
|
|
+ .communityPublish,
|
|
|
+ .communityDelete,
|
|
|
+ .communityVideoUploadAuth,
|
|
|
+ .communityImageUploadAuth,
|
|
|
+ .communityVideoList,
|
|
|
+ .communityFollowFeed,
|
|
|
+ .communityPostSuggest,
|
|
|
+ .communityTopicDetail,
|
|
|
+ .communityPostTopic,
|
|
|
+ .communityMemberFollowTopicList,
|
|
|
+ .communityMemberFollowTopicFollow,
|
|
|
+ .communityMemberFollowTopicCancelFollow,
|
|
|
+ .communityPostDetail,
|
|
|
+ .communityPostComments,
|
|
|
+ .communityPostReply,
|
|
|
+ .communityPostComment,
|
|
|
+ .communityPostDeleteComment,
|
|
|
+ .communityUploadMusic,
|
|
|
+ .communityRecMusicList,
|
|
|
+ .communityGetMusicCategory,
|
|
|
+ .communityCateMusicList
|
|
|
+ :
|
|
|
+ return (headerParameters(headerType: .tokenHeader) as! [String : String])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|