XYFeedAPIManager.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. //
  2. // XYFeedAPIManager.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/5/28.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYFeedAPIManager.h"
  9. /// 创建内容
  10. static NSString * const FEED_CREATE_FEED = @"api-app/v1/feed/createFeed";
  11. /// 获取相册
  12. static NSString * const FEED_GET_PHOTO_LIST = @"api-app/v1/feed/getPhotoList";
  13. /// 获取视频
  14. static NSString * const FEED_GET_VIDEO_LIST = @"api-app/v1/feed/getVideoList";
  15. /// 获取视频(游客)
  16. static NSString * const FEED_GET_VIDEO_LIST_GUEST = @"api-app/v1/feed/getVideoListGuest";
  17. /// 添加评论
  18. static NSString * const FEED_ADD_COMMENT = @"api-app/v1/feed/addComment";
  19. /// 获取评论
  20. static NSString * const FEED_GET_COMMENT_LIST = @"api-app/v1/feed/getCommentList";
  21. /// 获取子评论
  22. static NSString * const FEED_GET_CHILD_COMMENT_LIST = @"api-app/v1/feed/getChildCommentList";
  23. /// 添加动作
  24. static NSString * const FEED_ADD_ACTION = @"api-app/v1/feed/addAction";
  25. /// 删除内容
  26. static NSString * const DEL_FEED_ACTION = @"api-app/v1/feed/delFeed";
  27. /// 发现
  28. static NSString * const FEED_FINDLIST_PATH = @"api-app/v1/feed/getVideoStreamList";
  29. /// 删除评论
  30. static NSString * const FEED_DELETE_COMMENT = @"api-app/v1/feed/delComment";
  31. /// 删除内容
  32. static NSString * const FEED_DELETE_FEED = @"api-app/v1/feed/delFeed";
  33. /// 添加内容查看数
  34. static NSString * const FEED_ADD_VIEW_COUNT = @"api-app/v1/feed/addViewCount";
  35. /// 获取内容详情
  36. static NSString * const FEED_GET_FEED_DEAIL = @"api-app/v1/feed/getFeedDetail";
  37. /// 创建照片墙
  38. static NSString * const FEED_CREATE_PHOTO_WALL = @"api-app/v1/feed/createPhotoWall";
  39. /// 获取照片墙列表
  40. static NSString * const FEED_GET_PHOTO_WALL_LIST = @"api-app/v1/feed/getPhotoWallList";
  41. /// 删除照片墙
  42. static NSString * const FEED_DELETE_PHOTO_WALL = @"api-app/v1/feed/deletePhotoWall";
  43. /// 获取内容按天分组分页列表
  44. static NSString * const FEED_GET_FEED_BY_DATA_PAGE_LIST = @"api-app/v1/feed/getFeedByDatePageList";
  45. /// 获取广场动态
  46. static NSString * const FEED_GET_SQUARE_FEED_LIST = @"api-app/v1/feed/getSquareFeedList";
  47. /// 点赞
  48. static NSString * const FEED_THUMBS_UP = @"api-app/v1/feed/thumbsUp";
  49. /// 随机获取一个三天内发表过状态的关注的用户
  50. static NSString * const FEED_USER_FOLLOW_NAME = @"api-app/v1/feed/getUserFollowName";
  51. /// 获取首页资讯接口
  52. static NSString * const FEED_GET_FEED_ACTIVITY_INFO_LIST = @"api-app/v1/feed/getFeedActivityInfoList";
  53. @implementation XYFeedAPIManager
  54. /// 创建内容
  55. /// @param parameters 参数 https://pt.laylib.com/console/api?p=120592570081591296&i=1162
  56. /// @param successHandler 请求成功
  57. /// @param failureHandler 请求失败
  58. - (NSNumber *)createFeedWithParameters:(NSDictionary *)parameters successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  59. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  60. config.urlPath = [FEED_CREATE_FEED copy];
  61. config.instructions = @"创建内容";
  62. config.requestParameters = parameters;
  63. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  64. }
  65. /// 获取相册
  66. /// @param lastId 最后一条id
  67. /// @param userId 用户id 不传看自己
  68. /// @param successHandler 请求成功
  69. /// @param failureHandler 请求失败
  70. - (NSNumber *)getPhotoListWithLastId:(NSString *)lastId userId:(NSString *)userId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  71. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  72. config.urlPath = [FEED_GET_PHOTO_LIST copy];
  73. config.instructions = @"获取相册";
  74. config.requestType = ZYLNetworkRequestTypeGet;
  75. NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
  76. [parameters setObject:lastId forKey:@"lastId"];
  77. if (StringIsNotEmpty(userId) && ![userId isEqualToString:[XYUserInfoManager nowUser].userId]) {
  78. [parameters setObject:userId forKey:@"userId"];
  79. }
  80. config.requestParameters = parameters;
  81. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  82. }
  83. /// 获取视频列表
  84. /// @param lastId 最后一条id
  85. /// @param userId 用户id 不传看自己
  86. /// @param successHandler 请求成功
  87. /// @param failureHandler 请求失败
  88. - (NSNumber *)getVideoListWithLastId:(NSString *)lastId userId:(NSString *)userId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  89. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  90. if ([XYUserInfoManager nowUser]) {
  91. config.urlPath = [FEED_GET_VIDEO_LIST copy];
  92. config.instructions = @"获取视频列表";
  93. }else {
  94. config.urlPath = [FEED_GET_VIDEO_LIST_GUEST copy];
  95. config.instructions = @"获取视频(游客)";
  96. }
  97. config.requestType = ZYLNetworkRequestTypeGet;
  98. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  99. [parameters addEntriesFromDictionary:@{@"lastId":lastId}];
  100. if (StringIsNotEmpty(userId) && ![userId isEqualToString:[XYUserInfoManager nowUser].userId]) {
  101. [parameters addEntriesFromDictionary:@{@"userId":userId}];
  102. }
  103. config.requestParameters = parameters;
  104. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  105. }
  106. /// 添加评论
  107. /// @param feedId 内容id
  108. /// @param replyId 答复id
  109. /// @param origReplyId 最顶层答复id
  110. /// @param replyUserId 答复用户id
  111. /// @param content 评论内容
  112. /// @param successHandler 请求成功
  113. /// @param failureHandler 请求失败
  114. - (NSNumber *)feedAddCommentWithFeedId:(NSString *)feedId replyId:(NSString *)replyId origReplyId:(NSString *)origReplyId replyUserId:(NSString *)replyUserId content:(NSString *)content successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  115. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  116. config.urlPath = [FEED_ADD_COMMENT copy];
  117. config.instructions = @"添加评论";
  118. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  119. [parameters addEntriesFromDictionary:@{@"feedId":feedId}];
  120. if (StringIsNotEmpty(replyId)) {
  121. [parameters addEntriesFromDictionary:@{@"replyId":replyId}];
  122. }
  123. if (StringIsNotEmpty(origReplyId)) {
  124. [parameters addEntriesFromDictionary:@{@"origReplyId":origReplyId}];
  125. }
  126. if (StringIsNotEmpty(replyUserId)) {
  127. [parameters addEntriesFromDictionary:@{@"replyUserId":replyUserId}];
  128. }
  129. if (StringIsNotEmpty(content)) {
  130. [parameters addEntriesFromDictionary:@{@"content":content}];
  131. }
  132. config.requestParameters = parameters;
  133. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  134. }
  135. /// 获取评论
  136. /// @param feedId 内容id
  137. /// @param lastId 分页id
  138. /// @param successHandler 请求成功
  139. /// @param failureHandler 请求失败
  140. - (NSNumber *)getCommentListWithFeedId:(NSString *)feedId lastId:(NSString *)lastId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  141. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  142. config.urlPath = [FEED_GET_COMMENT_LIST copy];
  143. config.instructions = @"获取评论";
  144. config.requestType = ZYLNetworkRequestTypeGet;
  145. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  146. [parameters addEntriesFromDictionary:@{@"feedId":feedId}];
  147. if (StringIsNotEmpty(lastId)) {
  148. [parameters addEntriesFromDictionary:@{@"lastId":lastId}];
  149. }
  150. config.requestParameters = parameters;
  151. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  152. }
  153. /// 获取子评论
  154. /// @param lastId 最后一条id
  155. /// @param commentId 当前评论的id
  156. /// @param successHandler 请求成功
  157. /// @param failureHandler 请求失败
  158. - (NSNumber *)getChildCommentListWithLastId:(NSString *)lastId commentId:(NSString *)commentId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  159. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  160. config.urlPath = [FEED_GET_CHILD_COMMENT_LIST copy];
  161. config.instructions = @"获取子评论";
  162. config.requestType = ZYLNetworkRequestTypeGet;
  163. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  164. [parameters addEntriesFromDictionary:@{@"commentId":commentId}];
  165. if (StringIsNotEmpty(lastId)) {
  166. [parameters addEntriesFromDictionary:@{@"lastId":lastId}];
  167. }
  168. config.requestParameters = parameters;
  169. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  170. }
  171. /// 添加动作
  172. /// @param targetId 目标id
  173. /// @param actionType 动作类型 点赞:10 点赞取消:11 收藏:20 收藏-取消:21 分享:30
  174. /// @param targetType 目标类型 图文:10 照片:20 视频:30 评论:40
  175. /// @param successHandler 请求成功
  176. /// @param failureHandler 请求失败
  177. - (NSNumber *)addActionWithTargetId:(NSString *)targetId actionType:(NSInteger)actionType targetType:(NSInteger)targetType successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  178. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  179. config.urlPath = [FEED_ADD_ACTION copy];
  180. config.instructions = @"添加动作";
  181. config.requestParameters = @{@"targetId":targetId, @"actionType":@(actionType), @"targetType":@(targetType)};
  182. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  183. }
  184. //发现
  185. //Query lastId 最后一条id Long
  186. - (NSNumber *)getVideoStreamListWithLastId:(NSString *)lastId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler{
  187. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  188. config.urlPath = [FEED_FINDLIST_PATH copy];
  189. config.instructions = @"发现";
  190. NSMutableDictionary *parm = [[NSMutableDictionary alloc] init];
  191. [parm setObject:lastId forKey:@"lastId"];
  192. config.requestParameters = parm;
  193. config.requestType = ZYLNetworkRequestTypeGet;
  194. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  195. }
  196. /// 删除评论
  197. /// @param commentId 评论id
  198. /// @param successHandler 请求成功
  199. /// @param failureHandler 请求失败
  200. - (NSNumber *)delCommentWithCommentId:(NSString *)commentId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  201. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  202. config.urlPath = [FEED_DELETE_COMMENT copy];
  203. config.instructions = @"删除评论";
  204. config.requestParameters = @{@"commentId":commentId};
  205. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  206. }
  207. /// 删除内容
  208. /// @param feedId 内容id
  209. /// @param successHandler 请求成功
  210. /// @param failureHandler 请求失败
  211. - (NSNumber *)delFeedWithFeedId:(NSString *)feedId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  212. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  213. config.urlPath = [FEED_DELETE_FEED copy];
  214. config.instructions = @"删除内容";
  215. config.requestParameters = @{@"feedId":feedId};
  216. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  217. }
  218. /// 添加内容查看数
  219. /// @param feedId 内容id
  220. /// @param successHandler 请求成功
  221. /// @param failureHandler 请求失败
  222. - (NSNumber *)addViewCountWithFeedId:(NSString *)feedId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  223. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  224. config.urlPath = [FEED_ADD_VIEW_COUNT copy];
  225. config.instructions = @"添加内容查看数";
  226. config.requestParameters = @{@"feedId":feedId};
  227. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  228. }
  229. //获取内容详情
  230. //Query feedId 内容Id Long
  231. - (NSNumber *)getFeedDetailWithFeedId:(NSString *)feedId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler{
  232. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  233. config.urlPath = [FEED_GET_FEED_DEAIL copy];
  234. config.instructions = @"获取内容详情";
  235. NSMutableDictionary *parm = [[NSMutableDictionary alloc] init];
  236. [parm setObject:feedId forKey:@"feedId"];
  237. config.requestParameters = parm;
  238. config.requestType = ZYLNetworkRequestTypeGet;
  239. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  240. }
  241. /// 创建照片墙
  242. /// @param url 照片链接地址
  243. /// @param successHandler 请求成功
  244. /// @param failureHandler 请求失败
  245. - (NSNumber *)createPhotoWallWithUrl:(NSString *)url successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  246. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  247. config.urlPath = [FEED_CREATE_PHOTO_WALL copy];
  248. config.instructions = @"创建照片墙";
  249. config.requestParameters = @{@"url":url};
  250. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  251. }
  252. /// 获取照片墙
  253. /// @param userId 用户id 不传则查询自己的照片墙
  254. /// @param successHandler 请求成功
  255. /// @param failureHandler 请求失败
  256. - (NSNumber *)getPhotoWallWithUserId:(NSString *)userId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  257. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  258. config.urlPath = [FEED_GET_PHOTO_WALL_LIST copy];
  259. config.instructions = @"获取照片墙";
  260. config.requestType = ZYLNetworkRequestTypeGet;
  261. if (![[XYUserInfoManager nowUser].userId isEqualToString:userId] && StringIsNotEmpty(userId)) {
  262. config.requestParameters = @{@"userId":userId};
  263. }
  264. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  265. }
  266. /// 删除照片墙
  267. /// @param photoWallId 照片墙id
  268. /// @param successHandler 请求成功
  269. /// @param failureHandler 请求失败
  270. - (NSNumber *)deletePhotoWallWithiPhotoWallId:(NSString *)photoWallId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  271. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  272. config.urlPath = [FEED_DELETE_PHOTO_WALL copy];
  273. config.instructions = @"删除照片墙";
  274. config.requestParameters = @{@"id":photoWallId};
  275. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  276. }
  277. /// 获取内容按天分组分页列表
  278. /// @param userId 用户id
  279. /// @param pageNum 当前页码
  280. /// @param pageSize 分页大小
  281. /// @param successHandler 请求成功
  282. /// @param failureHandler 请求失败
  283. - (NSNumber *)getFeedByDatePageListWithUserId:(NSString *)userId pageNum:(NSInteger)pageNum pageSize:(NSInteger)pageSize successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  284. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  285. config.urlPath = [FEED_GET_FEED_BY_DATA_PAGE_LIST copy];
  286. config.instructions = @"获取内容按天分组分页列表";
  287. config.requestType = ZYLNetworkRequestTypeGet;
  288. if (StringIsEmpty(userId)) {
  289. config.requestParameters = @{@"userId":@"0", @"pageNum":@(pageNum), @"pageSize":@(pageSize)};
  290. }else {
  291. config.requestParameters = @{@"userId":userId, @"pageNum":@(pageNum), @"pageSize":@(pageSize)};
  292. }
  293. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  294. }
  295. /// 获取广场动态
  296. /// @param pageNum 当前页码
  297. /// @param pageSize 分页大小
  298. /// @param successHandler 请求成功
  299. /// @param failureHandler 请求失败
  300. - (NSNumber *)getSquareFeedListWithPageNum:(NSInteger)pageNum pageSize:(NSInteger)pageSize successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  301. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  302. config.urlPath = [FEED_GET_SQUARE_FEED_LIST copy];
  303. config.instructions = @"获取广场动态";
  304. config.requestType = ZYLNetworkRequestTypeGet;
  305. config.requestParameters = @{@"pageNum":@(pageNum), @"pageSize":@(pageSize)};
  306. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  307. }
  308. /// 动态点赞
  309. /// @param feedId 动态ID
  310. /// @param successHandler 请求成功
  311. /// @param failureHandler 请求失败
  312. - (NSNumber *)thumbsUpWithFeedId:(NSString *)feedId successHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  313. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  314. config.urlPath = [FEED_THUMBS_UP copy];
  315. config.instructions = @"动态点赞";
  316. config.requestType = ZYLNetworkRequestTypeGet;
  317. config.requestParameters = @{@"feedId":feedId};
  318. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  319. }
  320. /// 随机获取一个三天内发表过状态的关注的用户
  321. /// @param successHandler 请求成功
  322. /// @param failureHandler 请求失败
  323. - (NSNumber *)getUserFollowNameSuccessHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  324. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  325. config.urlPath = [FEED_USER_FOLLOW_NAME copy];
  326. config.instructions = @"随机获取一个三天内发表过状态的关注的用户";
  327. config.requestType = ZYLNetworkRequestTypeGet;
  328. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  329. }
  330. /// 获取首页资讯接口
  331. /// @param successHandler 请求成功
  332. /// @param failureHandler 请求失败
  333. - (NSNumber *)getFeedActivityInfoListSuccessHandler:(ZYLNetworkTaskSuccessHandler)successHandler failureHandler:(ZYLNetworkTaskFailureHandler)failureHandler {
  334. ZYLDataAPIConfiguration *config = [ZYLDataAPIConfiguration new];
  335. config.urlPath = [FEED_GET_FEED_ACTIVITY_INFO_LIST copy];
  336. config.instructions = @"获取首页资讯接口";
  337. config.requestType = ZYLNetworkRequestTypeGet;
  338. return [super dispatchDataTaskWithConfiguration:config successHandler:successHandler failureHandler:failureHandler];
  339. }
  340. @end