common_newsfeed.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. import 'package:domain/constants/api_constants.dart';
  2. import 'package:domain/entity/myfollowing_list_entity.dart';
  3. import 'package:domain/entity/myposts_newsfeed_entity.dart';
  4. import 'package:domain/entity/newsfeed_comment_publish_entity.dart';
  5. import 'package:domain/entity/newsfeed_detail_entity.dart';
  6. import 'package:domain/entity/newsfeed_following_entity.dart';
  7. import 'package:domain/entity/newsfeed_foryou_entity.dart';
  8. import 'package:domain/entity/newsfeed_news_entity.dart';
  9. import 'package:domain/entity/server_time.dart';
  10. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  11. import 'package:plugin_platform/platform_export.dart';
  12. import 'package:plugin_platform/http/dio_engine.dart';
  13. import 'package:plugin_platform/http/http_result.dart';
  14. import 'package:riverpod_annotation/riverpod_annotation.dart';
  15. import 'package:shared/utils/log_utils.dart';
  16. import 'package:shared/utils/util.dart';
  17. import 'package:flutter_riverpod/flutter_riverpod.dart';
  18. import 'package:plugin_basic/provider/http_provider/http_provider.dart';
  19. part 'common_newsfeed.g.dart';
  20. @Riverpod(keepAlive: true)
  21. CommonNewsFeedRespository commonNewsFeedRespository(Ref ref) {
  22. final dioEngine = ref.watch(dioEngineProvider);
  23. return CommonNewsFeedRespository(dioEngine: dioEngine);
  24. }
  25. /*
  26. * 数据仓库
  27. */
  28. class CommonNewsFeedRespository {
  29. DioEngine dioEngine;
  30. CommonNewsFeedRespository({required this.dioEngine});
  31. // news feed - news 列表
  32. Future<HttpResult<Object>> fetchNewsList(
  33. Map<String, dynamic>? data, {
  34. CancelToken? cancelToken,
  35. }) async {
  36. Map<String, dynamic> params = {};
  37. params = data!;
  38. Map<String, String> headers = {};
  39. headers["Content-Type"] = "application/x-www-form-urlencoded";
  40. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  41. final result = await dioEngine.requestNetResult(
  42. // ApiConstants.apiServerTime, // api 地址
  43. '/api/v1/user/news-feed/feed/news', // api 地址
  44. params: params,
  45. headers: headers,
  46. method: HttpMethod.GET,
  47. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  48. networkDebounce: false, //是否防抖防止重复请求
  49. cancelToken: cancelToken,
  50. );
  51. //根据返回的结果,封装原始数据为Bean/Entity对象
  52. if (result.isSuccess) {
  53. //重新赋值data或list
  54. final json = result.getDataJson();
  55. var data = NewsfeedNewsEntity.fromJson(json!);
  56. //重新赋值data或list
  57. return result.convert(data: data);
  58. }else {
  59. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  60. ToastEngine.show("${result.errorMsg}");
  61. }
  62. }
  63. return result.convert();
  64. }
  65. // news feed - following 列表
  66. Future<HttpResult<Object>> fetchFollowingList(
  67. Map<String, dynamic>? data, {
  68. CancelToken? cancelToken,
  69. }) async {
  70. Map<String, dynamic> params = {};
  71. params = data!;
  72. Map<String, String> headers = {};
  73. headers["Content-Type"] = "application/x-www-form-urlencoded";
  74. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  75. final result = await dioEngine.requestNetResult(
  76. // ApiConstants.apiServerTime, // api 地址
  77. '/api/v1/user/news-feed/feed/following', // api 地址
  78. params: params,
  79. headers: headers,
  80. method: HttpMethod.GET,
  81. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  82. networkDebounce: false, //是否防抖防止重复请求
  83. cancelToken: cancelToken,
  84. );
  85. //根据返回的结果,封装原始数据为Bean/Entity对象
  86. if (result.isSuccess) {
  87. //重新赋值data或list
  88. final json = result.getDataJson();
  89. var data = NewsfeedFollowingEntity.fromJson(json!);
  90. //重新赋值data或list
  91. return result.convert(data: data);
  92. }else {
  93. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  94. ToastEngine.show("${result.errorMsg}");
  95. }
  96. }
  97. return result.convert();
  98. }
  99. // news feed - foryou 列表
  100. Future<HttpResult<Object>> fetchForyouList(
  101. Map<String, dynamic>? data, {
  102. CancelToken? cancelToken,
  103. }) async {
  104. Map<String, dynamic> params = {};
  105. params = data!;
  106. Map<String, String> headers = {};
  107. headers["Content-Type"] = "application/x-www-form-urlencoded";
  108. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  109. final result = await dioEngine.requestNetResult(
  110. // ApiConstants.apiServerTime, // api 地址
  111. '/api/v1/user/news-feed/feed/for-you', // api 地址
  112. params: params,
  113. headers: headers,
  114. method: HttpMethod.GET,
  115. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  116. networkDebounce: false, //是否防抖防止重复请求
  117. cancelToken: cancelToken,
  118. );
  119. //根据返回的结果,封装原始数据为Bean/Entity对象
  120. if (result.isSuccess) {
  121. //重新赋值data或list
  122. final json = result.getDataJson();
  123. var data = NewsfeedForyouEntity.fromJson(json!);
  124. //重新赋值data或list
  125. return result.convert(data: data);
  126. }else {
  127. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  128. ToastEngine.show("${result.errorMsg}");
  129. }
  130. }
  131. return result.convert();
  132. }
  133. // 获取 详情信息
  134. Future<HttpResult<Object>> fetchNewsFeedDetailInfo(
  135. Map<String, dynamic>? data, {
  136. CancelToken? cancelToken,
  137. }) async {
  138. Map<String, dynamic> params = {};
  139. params = data!;
  140. Map<String, String> headers = {};
  141. headers["Content-Type"] = "application/x-www-form-urlencoded";
  142. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  143. final result = await dioEngine.requestNetResult(
  144. // ApiConstants.apiServerTime, // api 地址
  145. '/api/v1/user/news-feed/feed/detail', // api 地址
  146. params: params,
  147. headers: headers,
  148. method: HttpMethod.GET,
  149. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  150. networkDebounce: true, //是否防抖防止重复请求
  151. cancelToken: cancelToken,
  152. );
  153. //根据返回的结果,封装原始数据为Bean/Entity对象
  154. if (result.isSuccess) {
  155. //重新赋值data或list
  156. final json = result.getDataJson();
  157. var data = NewsfeedDetailEntity.fromJson(json!);
  158. //重新赋值data或list
  159. return result.convert(data: data);
  160. }else {
  161. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  162. ToastEngine.show("${result.errorMsg}");
  163. }
  164. }
  165. return result.convert();
  166. }
  167. // 提交评论
  168. Future<HttpResult<Object>> fetchNewsfeedCommentSubmit(
  169. Map<String, dynamic>? data, {
  170. CancelToken? cancelToken,
  171. }) async {
  172. Map<String, dynamic> params = {};
  173. params = data!;
  174. Map<String, String> headers = {};
  175. headers["Content-Type"] = "application/x-www-form-urlencoded";
  176. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  177. final result = await dioEngine.requestNetResult(
  178. // ApiConstants.apiServerTime, // api 地址
  179. '/api/v1/user/news-feed/comment/publish', // api 地址
  180. params: params,
  181. headers: headers,
  182. method: HttpMethod.POST,
  183. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  184. networkDebounce: true, //是否防抖防止重复请求
  185. cancelToken: cancelToken,
  186. );
  187. //根据返回的结果,封装原始数据为Bean/Entity对象
  188. if (result.isSuccess) {
  189. //重新赋值data或list
  190. final json = result.getDataJson();
  191. var data = NewsfeedCommentPublishEntity.fromJson(json!);
  192. //重新赋值data或list
  193. return result.convert(data: data);
  194. }else {
  195. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  196. ToastEngine.show("${result.errorMsg}");
  197. }
  198. }
  199. return result.convert();
  200. }
  201. // news feed - post 发布newsfeed
  202. Future<HttpResult<Object>> fetchNewsfeedPublish(
  203. Map<String, dynamic>? data, {
  204. CancelToken? cancelToken,
  205. }) async {
  206. Map<String, dynamic> params = {};
  207. params = data!;
  208. Map<String, String> headers = {};
  209. headers["Content-Type"] = "application/x-www-form-urlencoded";
  210. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  211. List<String> paths = data!["resources"] as List<String>;
  212. Map<String, String> files = {};
  213. if (paths != null && paths.isNotEmpty) {
  214. paths.asMap().forEach((index, path) {
  215. files["resources[$index]"] = path;
  216. });
  217. }
  218. // 删除 resources 属性
  219. params.remove("resources");
  220. final result = await dioEngine.requestNetResult(
  221. // ApiConstants.apiServerTime, // api 地址
  222. '/api/v1/user/news-feed/index/publish', // api 地址
  223. params: params,
  224. paths: files,
  225. headers: headers,
  226. method: HttpMethod.POST,
  227. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  228. networkDebounce: true, //是否防抖防止重复请求
  229. cancelToken: cancelToken,
  230. );
  231. //根据返回的结果,封装原始数据为Bean/Entity对象
  232. if (result.isSuccess) {
  233. //重新赋值data或list
  234. final json = result.getDataJson();
  235. // var data = NewsfeedCommentPublishEntity.fromJson(json!);
  236. //重新赋值data或list
  237. return result.convert(data: json);
  238. }else {
  239. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  240. ToastEngine.show("${result.errorMsg}");
  241. }
  242. }
  243. return result.convert();
  244. }
  245. // 获取 我关注的人
  246. Future<HttpResult<Object>> fetchMyFollowList(
  247. Map<String, dynamic>? data, {
  248. CancelToken? cancelToken,
  249. }) async {
  250. Map<String, dynamic> params = {};
  251. params = data!;
  252. Map<String, String> headers = {};
  253. headers["Content-Type"] = "application/x-www-form-urlencoded";
  254. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  255. final result = await dioEngine.requestNetResult(
  256. // ApiConstants.apiServerTime, // api 地址
  257. '/api/v1/user/me/index/follows', // api 地址
  258. params: params,
  259. headers: headers,
  260. method: HttpMethod.GET,
  261. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  262. networkDebounce: true, //是否防抖防止重复请求
  263. cancelToken: cancelToken,
  264. );
  265. //根据返回的结果,封装原始数据为Bean/Entity对象
  266. if (result.isSuccess) {
  267. //重新赋值data或list
  268. final ListJson = result.getListJson();
  269. var data = ListJson!.map((e) => MyfollowingListEntity.fromJson(e!)).toList();
  270. //重新赋值data或list
  271. return result.convert(list: data);
  272. }else {
  273. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  274. ToastEngine.show("${result.errorMsg}");
  275. }
  276. }
  277. return result.convert();
  278. }
  279. // 获取 关注我的人
  280. Future<HttpResult<Object>> fetchMyFlowerList(
  281. Map<String, dynamic>? data, {
  282. CancelToken? cancelToken,
  283. }) async {
  284. Map<String, dynamic> params = {};
  285. params = data!;
  286. Map<String, String> headers = {};
  287. headers["Content-Type"] = "application/x-www-form-urlencoded";
  288. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  289. final result = await dioEngine.requestNetResult(
  290. // ApiConstants.apiServerTime, // api 地址
  291. '/api/v1/user/me/index/flowers', // api 地址
  292. params: params,
  293. headers: headers,
  294. method: HttpMethod.GET,
  295. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  296. networkDebounce: true, //是否防抖防止重复请求
  297. cancelToken: cancelToken,
  298. );
  299. //根据返回的结果,封装原始数据为Bean/Entity对象
  300. if (result.isSuccess) {
  301. //重新赋值data或list
  302. final ListJson = result.getListJson();
  303. var data = ListJson!.map((e) => MyfollowingListEntity.fromJson(e!)).toList();
  304. //重新赋值data或list
  305. return result.convert(list: data);
  306. }else {
  307. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  308. ToastEngine.show("${result.errorMsg}");
  309. }
  310. }
  311. return result.convert();
  312. }
  313. // news feed 点赞/取消点赞
  314. Future<HttpResult<Object>> fetchLikeClick(
  315. Map<String, dynamic>? data, {
  316. CancelToken? cancelToken,
  317. }) async {
  318. Map<String, dynamic> params = {};
  319. params = data!;
  320. Map<String, String> headers = {};
  321. headers["Content-Type"] = "application/x-www-form-urlencoded";
  322. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  323. final result = await dioEngine.requestNetResult(
  324. // ApiConstants.apiServerTime, // api 地址
  325. '/api/v1/user/news-feed/like/click', // api 地址
  326. params: params,
  327. headers: headers,
  328. method: HttpMethod.POST,
  329. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  330. networkDebounce: true, //是否防抖防止重复请求
  331. cancelToken: cancelToken,
  332. );
  333. //根据返回的结果,封装原始数据为Bean/Entity对象
  334. if (result.isSuccess) {
  335. //重新赋值data或list
  336. final boolData = result.getDataDynamic();
  337. // var data = NewsfeedForyouEntity.fromJson(json!);
  338. //重新赋值data或list
  339. return result.convert(data: boolData);
  340. }else {
  341. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  342. ToastEngine.show("${result.errorMsg}");
  343. }
  344. }
  345. return result.convert();
  346. }
  347. // 关注/取消关注
  348. Future<HttpResult<Object>> handlerFollowOrCancel(
  349. Map<String, dynamic>? data, {
  350. CancelToken? cancelToken,
  351. }) async {
  352. Map<String, dynamic> params = {};
  353. params = data!;
  354. Map<String, String> headers = {};
  355. headers["Content-Type"] = "application/x-www-form-urlencoded";
  356. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  357. final result = await dioEngine.requestNetResult(
  358. // ApiConstants.apiServerTime, // api 地址
  359. '/api/v1/user/me/index/follow', // api 地址
  360. params: params,
  361. headers: headers,
  362. method: HttpMethod.POST,
  363. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  364. networkDebounce: true, //是否防抖防止重复请求
  365. cancelToken: cancelToken,
  366. );
  367. //根据返回的结果,封装原始数据为Bean/Entity对象
  368. if (result.isSuccess) {
  369. //重新赋值data或list
  370. final json = result.getDataJson();
  371. // var data = NewsfeedForyouEntity.fromJson(json!);
  372. //重新赋值data或list
  373. return result.convert(data: json);
  374. }else {
  375. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  376. ToastEngine.show("${result.errorMsg}");
  377. }
  378. }
  379. return result.convert();
  380. }
  381. // 获取 我发布的newsfeed
  382. Future<HttpResult<Object>> fetchMyPostNewsfeedList(
  383. Map<String, dynamic>? data, {
  384. CancelToken? cancelToken,
  385. }) async {
  386. Map<String, dynamic> params = {};
  387. params = data!;
  388. Map<String, String> headers = {};
  389. headers["Content-Type"] = "application/x-www-form-urlencoded";
  390. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  391. final result = await dioEngine.requestNetResult(
  392. // ApiConstants.apiServerTime, // api 地址
  393. '/api/v1/user/me/post/news-feed', // api 地址
  394. params: params,
  395. headers: headers,
  396. method: HttpMethod.GET,
  397. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  398. networkDebounce: true, //是否防抖防止重复请求
  399. cancelToken: cancelToken,
  400. );
  401. //根据返回的结果,封装原始数据为Bean/Entity对象
  402. if (result.isSuccess) {
  403. //重新赋值data或list
  404. final json = result.getDataJson();
  405. var data = MypostsNewsfeedEntity.fromJson(json!);
  406. //重新赋值data或list
  407. return result.convert(data: data);
  408. }else {
  409. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  410. ToastEngine.show("${result.errorMsg}");
  411. }
  412. }
  413. return result.convert();
  414. }
  415. // 获取 我发布的 garage
  416. Future<HttpResult<Object>> fetchMyPostGarageList(
  417. Map<String, dynamic>? data, {
  418. CancelToken? cancelToken,
  419. }) async {
  420. Map<String, dynamic> params = {};
  421. params = data!;
  422. Map<String, String> headers = {};
  423. headers["Content-Type"] = "application/x-www-form-urlencoded";
  424. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  425. final result = await dioEngine.requestNetResult(
  426. // ApiConstants.apiServerTime, // api 地址
  427. '/api/v1/user/me/post/garage-sale', // api 地址
  428. params: params,
  429. headers: headers,
  430. method: HttpMethod.GET,
  431. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  432. networkDebounce: true, //是否防抖防止重复请求
  433. cancelToken: cancelToken,
  434. );
  435. //根据返回的结果,封装原始数据为Bean/Entity对象
  436. if (result.isSuccess) {
  437. //重新赋值data或list
  438. final json = result.getDataJson();
  439. // var data = NewsfeedDetailEntity.fromJson(json!);
  440. //重新赋值data或list
  441. return result.convert(data: data);
  442. }else {
  443. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  444. ToastEngine.show("${result.errorMsg}");
  445. }
  446. }
  447. return result.convert();
  448. }
  449. }