common_newsfeed.dart 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import 'package:domain/constants/api_constants.dart';
  2. import 'package:domain/entity/newsfeed_foryou_entity.dart';
  3. import 'package:domain/entity/newsfeed_news_entity.dart';
  4. import 'package:domain/entity/server_time.dart';
  5. import 'package:plugin_platform/platform_export.dart';
  6. import 'package:plugin_platform/http/dio_engine.dart';
  7. import 'package:plugin_platform/http/http_result.dart';
  8. import 'package:riverpod_annotation/riverpod_annotation.dart';
  9. import 'package:shared/utils/log_utils.dart';
  10. import 'package:shared/utils/util.dart';
  11. import 'package:flutter_riverpod/flutter_riverpod.dart';
  12. import 'package:plugin_basic/provider/http_provider/http_provider.dart';
  13. part 'common_newsfeed.g.dart';
  14. @Riverpod(keepAlive: true)
  15. CommonNewsFeedRepository commonNewsFeedRepository(Ref ref) {
  16. final dioEngine = ref.watch(dioEngineProvider);
  17. return CommonNewsFeedRepository(dioEngine: dioEngine);
  18. }
  19. /*
  20. * 数据仓库
  21. */
  22. class CommonNewsFeedRepository {
  23. DioEngine dioEngine;
  24. CommonNewsFeedRepository({required this.dioEngine});
  25. // 获取 我关注的人
  26. Future<HttpResult<Object>> fetchMyFollowList(
  27. Map<String, dynamic>? data, {
  28. CancelToken? cancelToken,
  29. }) async {
  30. Map<String, dynamic> params = {};
  31. params = data!;
  32. Map<String, String> headers = {};
  33. headers["Content-Type"] = "application/x-www-form-urlencoded";
  34. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  35. final result = await dioEngine.requestNetResult(
  36. // ApiConstants.apiServerTime, // api 地址
  37. '/api/v1/user/me/index/follows', // api 地址
  38. params: params,
  39. headers: headers,
  40. method: HttpMethod.GET,
  41. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  42. networkDebounce: true, //是否防抖防止重复请求
  43. cancelToken: cancelToken,
  44. );
  45. //根据返回的结果,封装原始数据为Bean/Entity对象
  46. if (result.isSuccess) {
  47. //重新赋值data或list
  48. final json = result.getDataJson();
  49. // var data = NewsfeedForyouEntity.fromJson(json!);
  50. //重新赋值data或list
  51. return result.convert(data: json);
  52. }
  53. return result.convert();
  54. }
  55. // 获取 关注我的人
  56. Future<HttpResult<Object>> fetchMyFollowerList(
  57. Map<String, dynamic>? data, {
  58. CancelToken? cancelToken,
  59. }) async {
  60. Map<String, dynamic> params = {};
  61. params = data!;
  62. Map<String, String> headers = {};
  63. headers["Content-Type"] = "application/x-www-form-urlencoded";
  64. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  65. final result = await dioEngine.requestNetResult(
  66. // ApiConstants.apiServerTime, // api 地址
  67. '/api/v1/user/me/index/flowers', // api 地址
  68. params: params,
  69. headers: headers,
  70. method: HttpMethod.GET,
  71. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  72. networkDebounce: true, //是否防抖防止重复请求
  73. cancelToken: cancelToken,
  74. );
  75. //根据返回的结果,封装原始数据为Bean/Entity对象
  76. if (result.isSuccess) {
  77. //重新赋值data或list
  78. final json = result.getDataJson();
  79. // var data = NewsfeedForyouEntity.fromJson(json!);
  80. //重新赋值data或list
  81. return result.convert(data: json);
  82. }
  83. return result.convert();
  84. }
  85. // 关注/取消关注
  86. Future<HttpResult<Object>> handlerFollowOrCancel(
  87. Map<String, dynamic>? data, {
  88. CancelToken? cancelToken,
  89. }) async {
  90. Map<String, dynamic> params = {};
  91. params = data!;
  92. Map<String, String> headers = {};
  93. headers["Content-Type"] = "application/x-www-form-urlencoded";
  94. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  95. final result = await dioEngine.requestNetResult(
  96. // ApiConstants.apiServerTime, // api 地址
  97. '/api/v1/user/me/index/follow', // api 地址
  98. params: params,
  99. headers: headers,
  100. method: HttpMethod.POST,
  101. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  102. networkDebounce: true, //是否防抖防止重复请求
  103. cancelToken: cancelToken,
  104. );
  105. //根据返回的结果,封装原始数据为Bean/Entity对象
  106. if (result.isSuccess) {
  107. //重新赋值data或list
  108. final json = result.getDataJson();
  109. // var data = NewsfeedForyouEntity.fromJson(json!);
  110. //重新赋值data或list
  111. return result.convert(data: json);
  112. }
  113. return result.convert();
  114. }
  115. // 获取 我发布的newsfeed
  116. Future<HttpResult<Object>> fetchMyPostNewsfeedList(
  117. Map<String, dynamic>? data, {
  118. CancelToken? cancelToken,
  119. }) async {
  120. Map<String, dynamic> params = {};
  121. params = data!;
  122. Map<String, String> headers = {};
  123. headers["Content-Type"] = "application/x-www-form-urlencoded";
  124. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  125. final result = await dioEngine.requestNetResult(
  126. // ApiConstants.apiServerTime, // api 地址
  127. '/api/v1/user/me/post/news-feed', // api 地址
  128. params: params,
  129. headers: headers,
  130. method: HttpMethod.GET,
  131. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  132. networkDebounce: true, //是否防抖防止重复请求
  133. cancelToken: cancelToken,
  134. );
  135. //根据返回的结果,封装原始数据为Bean/Entity对象
  136. if (result.isSuccess) {
  137. //重新赋值data或list
  138. final json = result.getDataJson();
  139. // var data = NewsfeedDetailEntity.fromJson(json!);
  140. //重新赋值data或list
  141. return result.convert(data: data);
  142. }
  143. return result.convert();
  144. }
  145. // 获取 我发布的 garage
  146. Future<HttpResult<Object>> fetchMyPostGarageList(
  147. Map<String, dynamic>? data, {
  148. CancelToken? cancelToken,
  149. }) async {
  150. Map<String, dynamic> params = {};
  151. params = data!;
  152. Map<String, String> headers = {};
  153. headers["Content-Type"] = "application/x-www-form-urlencoded";
  154. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  155. final result = await dioEngine.requestNetResult(
  156. // ApiConstants.apiServerTime, // api 地址
  157. '/api/v1/user/me/post/garage-sale', // api 地址
  158. params: params,
  159. headers: headers,
  160. method: HttpMethod.GET,
  161. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  162. networkDebounce: true, //是否防抖防止重复请求
  163. cancelToken: cancelToken,
  164. );
  165. //根据返回的结果,封装原始数据为Bean/Entity对象
  166. if (result.isSuccess) {
  167. //重新赋值data或list
  168. final json = result.getDataJson();
  169. // var data = NewsfeedDetailEntity.fromJson(json!);
  170. //重新赋值data或list
  171. return result.convert(data: data);
  172. }
  173. return result.convert();
  174. }
  175. }