common_garage.dart 6.9 KB

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