property_resposity.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import 'package:domain/constants/api_constants.dart';
  2. import 'package:domain/entity/property_news_detail_entity.dart';
  3. import 'package:domain/entity/property_news_entity.dart';
  4. import 'package:domain/entity/property_sale_rent_entity.dart';
  5. import 'package:domain/entity/server_time.dart';
  6. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  7. import 'package:plugin_platform/platform_export.dart';
  8. import 'package:plugin_platform/http/dio_engine.dart';
  9. import 'package:plugin_platform/http/http_result.dart';
  10. import 'package:riverpod_annotation/riverpod_annotation.dart';
  11. import 'package:shared/utils/log_utils.dart';
  12. import 'package:shared/utils/util.dart';
  13. import 'package:flutter_riverpod/flutter_riverpod.dart';
  14. import 'package:plugin_basic/provider/http_provider/http_provider.dart';
  15. part 'property_resposity.g.dart';
  16. @Riverpod(keepAlive: true)
  17. PropertyRespository propertyRespository(Ref ref) {
  18. final dioEngine = ref.watch(dioEngineProvider);
  19. return PropertyRespository(dioEngine: dioEngine);
  20. }
  21. /*
  22. * 数据仓库
  23. */
  24. class PropertyRespository {
  25. DioEngine dioEngine;
  26. PropertyRespository({required this.dioEngine});
  27. // 获取 news 列表
  28. Future<HttpResult<Object>> fetchNewsList(
  29. Map<String, dynamic>? data, {
  30. CancelToken? cancelToken,
  31. }) async {
  32. Map<String, dynamic> params = {};
  33. params = data!;
  34. Map<String, String> headers = {};
  35. headers["Content-Type"] = "application/x-www-form-urlencoded";
  36. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  37. final result = await dioEngine.requestNetResult(
  38. // ApiConstants.apiServerTime, // api 地址
  39. '/api/v1/user/property/news/list', // api 地址
  40. params: params,
  41. headers: headers,
  42. method: HttpMethod.GET,
  43. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  44. networkDebounce: true, //是否防抖防止重复请求
  45. cancelToken: cancelToken,
  46. );
  47. Log.d("------请求返回的result--$result--------");
  48. //根据返回的结果,封装原始数据为Bean/Entity对象
  49. if (result.isSuccess) {
  50. //重新赋值data或list
  51. final json = result.getDataJson();
  52. var data = PropertyNewsEntity.fromJson(json!);
  53. //重新赋值data或list
  54. return result.convert<PropertyNewsEntity>(data: data);
  55. }else {
  56. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  57. ToastEngine.show("${result.errorMsg}");
  58. }
  59. }
  60. return result.convert();
  61. }
  62. // 获取 news 详情
  63. Future<HttpResult<Object>> fetchNewsDetail(
  64. Map<String, dynamic>? data, {
  65. CancelToken? cancelToken,
  66. }) async {
  67. Map<String, dynamic> params = {};
  68. params = data!;
  69. Map<String, String> headers = {};
  70. headers["Content-Type"] = "application/x-www-form-urlencoded";
  71. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  72. final result = await dioEngine.requestNetResult(
  73. // ApiConstants.apiServerTime, // api 地址
  74. '/api/v1/user/property/news/detail', // api 地址
  75. params: params,
  76. headers: headers,
  77. method: HttpMethod.GET,
  78. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  79. networkDebounce: true, //是否防抖防止重复请求
  80. cancelToken: cancelToken,
  81. );
  82. Log.d("------请求返回的result--$result--------");
  83. //根据返回的结果,封装原始数据为Bean/Entity对象
  84. if (result.isSuccess) {
  85. //重新赋值data或list
  86. final json = result.getDataJson();
  87. var data = PropertyNewsDetailEntity.fromJson(json!);
  88. //重新赋值data或list
  89. return result.convert<PropertyNewsDetailEntity>(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. // 点赞/取消点赞
  98. Future<HttpResult<Object>> fetchPropertyNewsLikeClick(
  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/property/like/click', // api 地址
  110. params: params,
  111. headers: headers,
  112. method: HttpMethod.POST,
  113. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  114. networkDebounce: true, //是否防抖防止重复请求
  115. cancelToken: cancelToken,
  116. );
  117. Log.d("------请求返回的result--$result--------");
  118. //根据返回的结果,封装原始数据为Bean/Entity对象
  119. if (result.isSuccess) {
  120. //重新赋值data或list
  121. final json = result.getDataJson();
  122. if(json!=null && json['data'] == true){
  123. return result.convert<bool>(data: true);
  124. }else {
  125. return result.convert<bool>(data: false);
  126. }
  127. }else {
  128. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  129. ToastEngine.show("${result.errorMsg}");
  130. }
  131. }
  132. return result.convert();
  133. }
  134. // 获取 transaction 列表 (rent sale)
  135. Future<HttpResult<Object>> fetchTransactionList(
  136. Map<String, dynamic>? data, {
  137. CancelToken? cancelToken,
  138. }) async {
  139. Map<String, dynamic> params = {};
  140. params = data!;
  141. Map<String, String> headers = {};
  142. headers["Content-Type"] = "application/x-www-form-urlencoded";
  143. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  144. final result = await dioEngine.requestNetResult(
  145. // ApiConstants.apiServerTime, // api 地址
  146. '/api/v1/user/property/transaction/list', // api 地址
  147. params: params,
  148. headers: headers,
  149. method: HttpMethod.GET,
  150. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  151. networkDebounce: true, //是否防抖防止重复请求
  152. cancelToken: cancelToken,
  153. );
  154. //根据返回的结果,封装原始数据为Bean/Entity对象
  155. if (result.isSuccess) {
  156. //重新赋值data或list
  157. final json = result.getDataJson();
  158. var data = PropertySaleRentEntity.fromJson(json!);
  159. //重新赋值data或list
  160. return result.convert(data: data);
  161. }else {
  162. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  163. ToastEngine.show("${result.errorMsg}");
  164. }
  165. }
  166. return result.convert();
  167. }
  168. }