common_garage.dart 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import 'package:domain/constants/api_constants.dart';
  2. import 'package:domain/entity/garage_sale_rent_detail_entity.dart';
  3. import 'package:domain/entity/garage_sale_rent_entity.dart';
  4. import 'package:domain/entity/myposts_sale_rent_entity.dart';
  5. import 'package:domain/entity/newsfeed_foryou_entity.dart';
  6. import 'package:domain/entity/newsfeed_news_entity.dart';
  7. import 'package:domain/entity/server_time.dart';
  8. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  9. import 'package:plugin_platform/platform_export.dart';
  10. import 'package:plugin_platform/http/dio_engine.dart';
  11. import 'package:plugin_platform/http/http_result.dart';
  12. import 'package:riverpod_annotation/riverpod_annotation.dart';
  13. import 'package:shared/utils/log_utils.dart';
  14. import 'package:shared/utils/util.dart';
  15. import 'package:flutter_riverpod/flutter_riverpod.dart';
  16. import 'package:plugin_basic/provider/http_provider/http_provider.dart';
  17. part 'common_garage.g.dart';
  18. @Riverpod(keepAlive: true)
  19. CommonGarageRespository commonGarageRespository(Ref ref) {
  20. final dioEngine = ref.watch(dioEngineProvider);
  21. return CommonGarageRespository(dioEngine: dioEngine);
  22. }
  23. /*
  24. * 数据仓库
  25. */
  26. class CommonGarageRespository {
  27. DioEngine dioEngine;
  28. CommonGarageRespository({required this.dioEngine});
  29. // garage 获取 分类 字典
  30. Future<HttpResult<Object>> fetchGarageCateGoryList(
  31. Map<String, dynamic>? data, {
  32. CancelToken? cancelToken,
  33. }) async {
  34. Map<String, dynamic> params = {};
  35. params = data!;
  36. Map<String, String> headers = {};
  37. headers["Content-Type"] = "application/x-www-form-urlencoded";
  38. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  39. final result = await dioEngine.requestNetResult(
  40. // ApiConstants.apiServerTime, // api 地址
  41. '/api/v1/user/garage-sale/category/index', // api 地址
  42. params: params,
  43. headers: headers,
  44. method: HttpMethod.GET,
  45. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  46. networkDebounce: true, //是否防抖防止重复请求
  47. cancelToken: cancelToken,
  48. );
  49. //根据返回的结果,封装原始数据为Bean/Entity对象
  50. if (result.isSuccess) {
  51. //重新赋值data或list
  52. final json = result.getDataJson();
  53. // var data = NewsfeedForyouEntity.fromJson(json!);
  54. //重新赋值data或list
  55. return result.convert(data: json);
  56. }else {
  57. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  58. ToastEngine.show("${result.errorMsg}");
  59. }
  60. }
  61. return result.convert();
  62. }
  63. // garage 获取 列表
  64. Future<HttpResult<Object>> fetchGarageDataList(
  65. Map<String, dynamic>? data, {
  66. CancelToken? cancelToken,
  67. }) async {
  68. Map<String, dynamic> params = {};
  69. params = data!;
  70. Map<String, String> headers = {};
  71. headers["Content-Type"] = "application/x-www-form-urlencoded";
  72. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  73. final result = await dioEngine.requestNetResult(
  74. // ApiConstants.apiServerTime, // api 地址
  75. '/api/v1/user/garage-sale/index/type', // api 地址
  76. params: params,
  77. headers: headers,
  78. method: HttpMethod.GET,
  79. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  80. networkDebounce: true, //是否防抖防止重复请求
  81. cancelToken: cancelToken,
  82. );
  83. //根据返回的结果,封装原始数据为Bean/Entity对象
  84. if (result.isSuccess) {
  85. //重新赋值data或list
  86. final json = result.getListJson();
  87. List<GarageSaleRentEntity> data = json?.map((item) => GarageSaleRentEntity.fromJson(item)).toList() ?? [];
  88. //重新赋值data或list
  89. return result.convert(list: data);
  90. }else {
  91. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  92. ToastEngine.show("${result.errorMsg}");
  93. }
  94. }
  95. return result.convert();
  96. }
  97. // myposts 中 garage 获取 列表
  98. Future<HttpResult<Object>> fetchMyPostsGarageDataList(
  99. Map<String, dynamic>? data, {
  100. CancelToken? cancelToken,
  101. }) async {
  102. Map<String, dynamic> params = {};
  103. params = data!;
  104. Map<String, String> headers = {};
  105. headers["Content-Type"] = "application/x-www-form-urlencoded";
  106. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  107. final result = await dioEngine.requestNetResult(
  108. // ApiConstants.apiServerTime, // api 地址
  109. '/api/v1/user/me/post/garage-sale', // api 地址
  110. params: params,
  111. headers: headers,
  112. method: HttpMethod.GET,
  113. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  114. networkDebounce: true, //是否防抖防止重复请求
  115. cancelToken: cancelToken,
  116. );
  117. //根据返回的结果,封装原始数据为Bean/Entity对象
  118. if (result.isSuccess) {
  119. //重新赋值data或list
  120. final json = result.getListJson();
  121. List<MypostsSaleRentEntity> data = json?.map((item) => MypostsSaleRentEntity.fromJson(item)).toList() ?? [];
  122. //重新赋值data或list
  123. return result.convert(list: data);
  124. }else {
  125. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  126. ToastEngine.show("${result.errorMsg}");
  127. }
  128. }
  129. return result.convert();
  130. }
  131. // garage 点赞/取消点赞
  132. Future<HttpResult<Object>> fetchGarageColleciton(
  133. Map<String, dynamic>? data, {
  134. CancelToken? cancelToken,
  135. }) async {
  136. Map<String, dynamic> params = {};
  137. params = data!;
  138. Map<String, String> headers = {};
  139. headers["Content-Type"] = "application/x-www-form-urlencoded";
  140. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  141. final result = await dioEngine.requestNetResult(
  142. // ApiConstants.apiServerTime, // api 地址
  143. '/api/v1/user/garage-sale/like/click', // api 地址
  144. params: params,
  145. headers: headers,
  146. method: HttpMethod.POST,
  147. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  148. networkDebounce: true, //是否防抖防止重复请求
  149. cancelToken: cancelToken,
  150. );
  151. //根据返回的结果,封装原始数据为Bean/Entity对象
  152. if (result.isSuccess) {
  153. //重新赋值data或list
  154. final json = result.getDataDynamic();
  155. // var data = NewsfeedForyouEntity.fromJson(json!);
  156. //重新赋值data或list
  157. return result.convert(data: json);
  158. }else {
  159. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  160. ToastEngine.show("${result.errorMsg}");
  161. }
  162. }
  163. return result.convert();
  164. }
  165. // 发布 garage
  166. Future<HttpResult<Object>> fetchPublishGarage(
  167. Map<String, dynamic>? data, {
  168. CancelToken? cancelToken,
  169. }) async {
  170. Map<String, dynamic> params = {};
  171. params = data!;
  172. Map<String, String> headers = {};
  173. headers["Content-Type"] = "application/x-www-form-urlencoded";
  174. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  175. final result = await dioEngine.requestNetResult(
  176. // ApiConstants.apiServerTime, // api 地址
  177. '/api/v1/user/garage-sale/index/publish', // api 地址
  178. params: params,
  179. headers: headers,
  180. method: HttpMethod.POST,
  181. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  182. networkDebounce: true, //是否防抖防止重复请求
  183. cancelToken: cancelToken,
  184. );
  185. //根据返回的结果,封装原始数据为Bean/Entity对象
  186. if (result.isSuccess) {
  187. //重新赋值data或list
  188. final json = result.getDataJson();
  189. // var data = NewsfeedForyouEntity.fromJson(json!);
  190. //重新赋值data或list
  191. return result.convert(data: json);
  192. }else {
  193. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  194. ToastEngine.show("${result.errorMsg}");
  195. }
  196. }
  197. return result.convert();
  198. }
  199. // 获取 详情信息
  200. Future<HttpResult<Object>> fetchGarageDetailInfo(
  201. Map<String, dynamic>? data, {
  202. CancelToken? cancelToken,
  203. }) async {
  204. Map<String, dynamic> params = {};
  205. params = data!;
  206. Map<String, String> headers = {};
  207. headers["Content-Type"] = "application/x-www-form-urlencoded";
  208. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  209. final result = await dioEngine.requestNetResult(
  210. // ApiConstants.apiServerTime, // api 地址
  211. '/api/v1/user/garage-sale/index/detail', // api 地址
  212. params: params,
  213. headers: headers,
  214. method: HttpMethod.GET,
  215. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  216. networkDebounce: true, //是否防抖防止重复请求
  217. cancelToken: cancelToken,
  218. );
  219. //根据返回的结果,封装原始数据为Bean/Entity对象
  220. if (result.isSuccess) {
  221. //重新赋值data或list
  222. final json = result.getDataJson();
  223. var data = GarageSaleRentDetailEntity.fromJson(json!);
  224. //重新赋值data或list
  225. return result.convert(data: data);
  226. }else {
  227. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  228. ToastEngine.show("${result.errorMsg}");
  229. }
  230. }
  231. return result.convert();
  232. }
  233. }