common_garage.dart 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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: false, //是否防抖防止重复请求
  81. cancelToken: cancelToken,
  82. );
  83. //根据返回的结果,封装原始数据为Bean/Entity对象
  84. if (result.isSuccess) {
  85. //重新赋值data或list
  86. final json = result.getDataJson();
  87. var data = GarageSaleRentEntity.fromJson(json!);
  88. //重新赋值data或list
  89. return result.convert(data: 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: false, //是否防抖防止重复请求
  115. cancelToken: cancelToken,
  116. );
  117. //根据返回的结果,封装原始数据为Bean/Entity对象
  118. if (result.isSuccess) {
  119. //重新赋值data或list
  120. final json = result.getDataJson();
  121. var data = MypostsSaleRentEntity.fromJson(json!);
  122. //重新赋值data或list
  123. return result.convert(data: 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. List<String> paths = data!["resources"] as List<String>;
  176. Map<String, String> files = {};
  177. if (paths != null && paths.isNotEmpty) {
  178. paths.asMap().forEach((index, path) {
  179. files["resources[$index]"] = path;
  180. });
  181. }
  182. // 删除 resources 属性
  183. params.remove("resources");
  184. final result = await dioEngine.requestNetResult(
  185. // ApiConstants.apiServerTime, // api 地址
  186. '/api/v1/user/garage-sale/index/publish', // api 地址
  187. params: params,
  188. paths: files,
  189. headers: headers,
  190. method: HttpMethod.POST,
  191. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  192. networkDebounce: true, //是否防抖防止重复请求
  193. cancelToken: cancelToken,
  194. );
  195. //根据返回的结果,封装原始数据为Bean/Entity对象
  196. if (result.isSuccess) {
  197. //重新赋值data或list
  198. final json = result.getDataJson();
  199. // var data = NewsfeedForyouEntity.fromJson(json!);
  200. //重新赋值data或list
  201. return result.convert(data: json);
  202. }else {
  203. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  204. ToastEngine.show("${result.errorMsg}");
  205. }
  206. }
  207. return result.convert();
  208. }
  209. // 获取 详情信息
  210. Future<HttpResult<Object>> fetchGarageDetailInfo(
  211. Map<String, dynamic>? data, {
  212. CancelToken? cancelToken,
  213. }) async {
  214. Map<String, dynamic> params = {};
  215. params = data!;
  216. Map<String, String> headers = {};
  217. // headers["Content-Type"] = "application/x-www-form-urlencoded";
  218. // headers["Accept"] = "application/x.yyjobs-api.v1+json";
  219. final result = await dioEngine.requestNetResult(
  220. // ApiConstants.apiServerTime, // api 地址
  221. '/api/v1/user/garage-sale/index/detail', // api 地址
  222. params: params,
  223. headers: headers,
  224. method: HttpMethod.GET,
  225. isShowLoadingDialog: false, //是否展示默认的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 = GarageSaleRentDetailEntity.fromJson(json!);
  234. //重新赋值data或list
  235. return result.convert(data: data);
  236. }else {
  237. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  238. ToastEngine.show("${result.errorMsg}");
  239. }
  240. }
  241. return result.convert();
  242. }
  243. }