common_newsfeed.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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: true, //是否防抖防止重复请求
  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: true, //是否防抖防止重复请求
  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: true, //是否防抖防止重复请求
  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"] = "multipart/form-data";
  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. final result = await dioEngine.requestNetResult(
  219. // ApiConstants.apiServerTime, // api 地址
  220. '/api/v1/user/news-feed/index/publish', // api 地址
  221. params: params,
  222. paths: files,
  223. headers: headers,
  224. method: HttpMethod.POST,
  225. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  226. networkDebounce: true, //是否防抖防止重复请求
  227. cancelToken: cancelToken,
  228. );
  229. //根据返回的结果,封装原始数据为Bean/Entity对象
  230. if (result.isSuccess) {
  231. //重新赋值data或list
  232. final json = result.getDataJson();
  233. // var data = NewsfeedCommentPublishEntity.fromJson(json!);
  234. //重新赋值data或list
  235. return result.convert(data: json);
  236. }else {
  237. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  238. ToastEngine.show("${result.errorMsg}");
  239. }
  240. }
  241. return result.convert();
  242. }
  243. // 获取 我关注的人
  244. Future<HttpResult<Object>> fetchMyFollowList(
  245. Map<String, dynamic>? data, {
  246. CancelToken? cancelToken,
  247. }) async {
  248. Map<String, dynamic> params = {};
  249. params = data!;
  250. Map<String, String> headers = {};
  251. headers["Content-Type"] = "application/x-www-form-urlencoded";
  252. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  253. final result = await dioEngine.requestNetResult(
  254. // ApiConstants.apiServerTime, // api 地址
  255. '/api/v1/user/me/index/follows', // api 地址
  256. params: params,
  257. headers: headers,
  258. method: HttpMethod.GET,
  259. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  260. networkDebounce: true, //是否防抖防止重复请求
  261. cancelToken: cancelToken,
  262. );
  263. //根据返回的结果,封装原始数据为Bean/Entity对象
  264. if (result.isSuccess) {
  265. //重新赋值data或list
  266. final ListJson = result.getListJson();
  267. var data = ListJson!.map((e) => MyfollowingListEntity.fromJson(e!)).toList();
  268. //重新赋值data或list
  269. return result.convert(list: data);
  270. }else {
  271. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  272. ToastEngine.show("${result.errorMsg}");
  273. }
  274. }
  275. return result.convert();
  276. }
  277. // 获取 关注我的人
  278. Future<HttpResult<Object>> fetchMyFlowerList(
  279. Map<String, dynamic>? data, {
  280. CancelToken? cancelToken,
  281. }) async {
  282. Map<String, dynamic> params = {};
  283. params = data!;
  284. Map<String, String> headers = {};
  285. headers["Content-Type"] = "application/x-www-form-urlencoded";
  286. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  287. final result = await dioEngine.requestNetResult(
  288. // ApiConstants.apiServerTime, // api 地址
  289. '/api/v1/user/me/index/flowers', // api 地址
  290. params: params,
  291. headers: headers,
  292. method: HttpMethod.GET,
  293. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  294. networkDebounce: true, //是否防抖防止重复请求
  295. cancelToken: cancelToken,
  296. );
  297. //根据返回的结果,封装原始数据为Bean/Entity对象
  298. if (result.isSuccess) {
  299. //重新赋值data或list
  300. final ListJson = result.getListJson();
  301. var data = ListJson!.map((e) => MyfollowingListEntity.fromJson(e!)).toList();
  302. //重新赋值data或list
  303. return result.convert(list: data);
  304. }else {
  305. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  306. ToastEngine.show("${result.errorMsg}");
  307. }
  308. }
  309. return result.convert();
  310. }
  311. // news feed 点赞/取消点赞
  312. Future<HttpResult<Object>> fetchLikeClick(
  313. Map<String, dynamic>? data, {
  314. CancelToken? cancelToken,
  315. }) async {
  316. Map<String, dynamic> params = {};
  317. params = data!;
  318. Map<String, String> headers = {};
  319. headers["Content-Type"] = "application/x-www-form-urlencoded";
  320. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  321. final result = await dioEngine.requestNetResult(
  322. // ApiConstants.apiServerTime, // api 地址
  323. '/api/v1/user/news-feed/like/click', // api 地址
  324. params: params,
  325. headers: headers,
  326. method: HttpMethod.POST,
  327. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  328. networkDebounce: true, //是否防抖防止重复请求
  329. cancelToken: cancelToken,
  330. );
  331. //根据返回的结果,封装原始数据为Bean/Entity对象
  332. if (result.isSuccess) {
  333. //重新赋值data或list
  334. final boolData = result.getDataDynamic();
  335. // var data = NewsfeedForyouEntity.fromJson(json!);
  336. //重新赋值data或list
  337. return result.convert(data: boolData);
  338. }else {
  339. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  340. ToastEngine.show("${result.errorMsg}");
  341. }
  342. }
  343. return result.convert();
  344. }
  345. // 关注/取消关注
  346. Future<HttpResult<Object>> handlerFollowOrCancel(
  347. Map<String, dynamic>? data, {
  348. CancelToken? cancelToken,
  349. }) async {
  350. Map<String, dynamic> params = {};
  351. params = data!;
  352. Map<String, String> headers = {};
  353. headers["Content-Type"] = "application/x-www-form-urlencoded";
  354. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  355. final result = await dioEngine.requestNetResult(
  356. // ApiConstants.apiServerTime, // api 地址
  357. '/api/v1/user/me/index/follow', // api 地址
  358. params: params,
  359. headers: headers,
  360. method: HttpMethod.POST,
  361. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  362. networkDebounce: true, //是否防抖防止重复请求
  363. cancelToken: cancelToken,
  364. );
  365. //根据返回的结果,封装原始数据为Bean/Entity对象
  366. if (result.isSuccess) {
  367. //重新赋值data或list
  368. final json = result.getDataJson();
  369. // var data = NewsfeedForyouEntity.fromJson(json!);
  370. //重新赋值data或list
  371. return result.convert(data: json);
  372. }else {
  373. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  374. ToastEngine.show("${result.errorMsg}");
  375. }
  376. }
  377. return result.convert();
  378. }
  379. // 获取 我发布的newsfeed
  380. Future<HttpResult<Object>> fetchMyPostNewsfeedList(
  381. Map<String, dynamic>? data, {
  382. CancelToken? cancelToken,
  383. }) async {
  384. Map<String, dynamic> params = {};
  385. params = data!;
  386. Map<String, String> headers = {};
  387. headers["Content-Type"] = "application/x-www-form-urlencoded";
  388. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  389. final result = await dioEngine.requestNetResult(
  390. // ApiConstants.apiServerTime, // api 地址
  391. '/api/v1/user/me/post/news-feed', // api 地址
  392. params: params,
  393. headers: headers,
  394. method: HttpMethod.GET,
  395. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  396. networkDebounce: true, //是否防抖防止重复请求
  397. cancelToken: cancelToken,
  398. );
  399. //根据返回的结果,封装原始数据为Bean/Entity对象
  400. if (result.isSuccess) {
  401. //重新赋值data或list
  402. final json = result.getDataJson();
  403. var data = MypostsNewsfeedEntity.fromJson(json!);
  404. //重新赋值data或list
  405. return result.convert(data: data);
  406. }else {
  407. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  408. ToastEngine.show("${result.errorMsg}");
  409. }
  410. }
  411. return result.convert();
  412. }
  413. // 获取 我发布的 garage
  414. Future<HttpResult<Object>> fetchMyPostGarageList(
  415. Map<String, dynamic>? data, {
  416. CancelToken? cancelToken,
  417. }) async {
  418. Map<String, dynamic> params = {};
  419. params = data!;
  420. Map<String, String> headers = {};
  421. headers["Content-Type"] = "application/x-www-form-urlencoded";
  422. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  423. final result = await dioEngine.requestNetResult(
  424. // ApiConstants.apiServerTime, // api 地址
  425. '/api/v1/user/me/post/garage-sale', // api 地址
  426. params: params,
  427. headers: headers,
  428. method: HttpMethod.GET,
  429. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  430. networkDebounce: true, //是否防抖防止重复请求
  431. cancelToken: cancelToken,
  432. );
  433. //根据返回的结果,封装原始数据为Bean/Entity对象
  434. if (result.isSuccess) {
  435. //重新赋值data或list
  436. final json = result.getDataJson();
  437. // var data = NewsfeedDetailEntity.fromJson(json!);
  438. //重新赋值data或list
  439. return result.convert(data: data);
  440. }else {
  441. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  442. ToastEngine.show("${result.errorMsg}");
  443. }
  444. }
  445. return result.convert();
  446. }
  447. }