common_newsfeed.dart 17 KB

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