common_garage.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. // 更新 发布的 garage
  210. Future<HttpResult<Object>> updateMyGarage(
  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. List<String> paths = data!["resources"] as List<String>;
  220. Map<String, String> files = {};
  221. if (paths != null && paths.isNotEmpty) {
  222. paths.asMap().forEach((index, path) {
  223. files["resources[$index]"] = path;
  224. });
  225. }
  226. // 删除 resources 属性
  227. params.remove("resources");
  228. final result = await dioEngine.requestNetResult(
  229. // ApiConstants.apiServerTime, // api 地址
  230. '/api/v1/user/garage-sale/index/update', // api 地址
  231. params: params,
  232. paths: files,
  233. headers: headers,
  234. method: HttpMethod.POST,
  235. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  236. networkDebounce: true, //是否防抖防止重复请求
  237. cancelToken: cancelToken,
  238. );
  239. //根据返回的结果,封装原始数据为Bean/Entity对象
  240. if (result.isSuccess) {
  241. //重新赋值data或list
  242. final json = result.getDataJson();
  243. // var data = NewsfeedForyouEntity.fromJson(json!);
  244. //重新赋值data或list
  245. return result.convert(data: json);
  246. }else {
  247. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  248. ToastEngine.show("${result.errorMsg}");
  249. }
  250. }
  251. return result.convert();
  252. }
  253. // 删除 发布的 garage
  254. Future<HttpResult<Object>> deleteMyGarage(
  255. Map<String, dynamic>? data, {
  256. CancelToken? cancelToken,
  257. }) async {
  258. Map<String, dynamic> params = {};
  259. params = data!;
  260. Map<String, String> headers = {};
  261. headers["Content-Type"] = "application/x-www-form-urlencoded";
  262. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  263. // List<String> paths = data!["resources"] as List<String>;
  264. // Map<String, String> files = {};
  265. // if (paths != null && paths.isNotEmpty) {
  266. // paths.asMap().forEach((index, path) {
  267. // files["resources[$index]"] = path;
  268. // });
  269. // }
  270. // 删除 resources 属性
  271. // params.remove("resources");
  272. final result = await dioEngine.requestNetResult(
  273. '/api/v1/user/garage-sale/index/delete', // api 地址
  274. params: params,
  275. // paths: files,
  276. headers: headers,
  277. method: HttpMethod.POST,
  278. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  279. networkDebounce: true, //是否防抖防止重复请求
  280. cancelToken: cancelToken,
  281. );
  282. //根据返回的结果,封装原始数据为Bean/Entity对象
  283. if (result.isSuccess) {
  284. //重新赋值data或list
  285. final json = result.getDataJson();
  286. // var data = NewsfeedForyouEntity.fromJson(json!);
  287. //重新赋值data或list
  288. return result.convert(data: json);
  289. }else {
  290. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  291. ToastEngine.show("${result.errorMsg}");
  292. }
  293. }
  294. return result.convert();
  295. }
  296. // 获取 详情信息
  297. Future<HttpResult<Object>> fetchGarageDetailInfo(
  298. Map<String, dynamic>? data, {
  299. CancelToken? cancelToken,
  300. }) async {
  301. Map<String, dynamic> params = {};
  302. params = data!;
  303. Map<String, String> headers = {};
  304. // headers["Content-Type"] = "application/x-www-form-urlencoded";
  305. // headers["Accept"] = "application/x.yyjobs-api.v1+json";
  306. final result = await dioEngine.requestNetResult(
  307. // ApiConstants.apiServerTime, // api 地址
  308. '/api/v1/user/garage-sale/index/detail', // api 地址
  309. params: params,
  310. headers: headers,
  311. method: HttpMethod.GET,
  312. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  313. networkDebounce: true, //是否防抖防止重复请求
  314. cancelToken: cancelToken,
  315. );
  316. //根据返回的结果,封装原始数据为Bean/Entity对象
  317. if (result.isSuccess) {
  318. //重新赋值data或list
  319. final json = result.getDataJson();
  320. var data = GarageSaleRentDetailEntity.fromJson(json!);
  321. //重新赋值data或list
  322. return result.convert(data: data);
  323. }else {
  324. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  325. ToastEngine.show("${result.errorMsg}");
  326. }
  327. }
  328. return result.convert();
  329. }
  330. }