property_resposity.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import 'package:domain/constants/api_constants.dart';
  2. import 'package:domain/entity/property_news_entity.dart';
  3. import 'package:domain/entity/property_sale_rent_entity.dart';
  4. import 'package:domain/entity/server_time.dart';
  5. import 'package:plugin_platform/engine/toast/toast_engine.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 'property_resposity.g.dart';
  15. @Riverpod(keepAlive: true)
  16. PropertyRespository propertyRespository(Ref ref) {
  17. final dioEngine = ref.watch(dioEngineProvider);
  18. return PropertyRespository(dioEngine: dioEngine);
  19. }
  20. /*
  21. * 数据仓库
  22. */
  23. class PropertyRespository {
  24. DioEngine dioEngine;
  25. PropertyRespository({required this.dioEngine});
  26. // 获取 news 列表
  27. Future<HttpResult<Object>> fetchNewsList(
  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/property/news/list', // api 地址
  39. params: params,
  40. headers: headers,
  41. method: HttpMethod.GET,
  42. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  43. networkDebounce: true, //是否防抖防止重复请求
  44. cancelToken: cancelToken,
  45. );
  46. Log.d("------请求返回的result--$result--------");
  47. //根据返回的结果,封装原始数据为Bean/Entity对象
  48. if (result.isSuccess) {
  49. //重新赋值data或list
  50. final json = result.getDataJson();
  51. var data = PropertyNewsEntity.fromJson(json!);
  52. //重新赋值data或list
  53. return result.convert<PropertyNewsEntity>(data: data);
  54. }else {
  55. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  56. ToastEngine.show("${result.errorMsg}");
  57. }
  58. }
  59. return result.convert();
  60. }
  61. // 点赞/取消点赞
  62. Future<HttpResult<Object>> fetchPropertyNewsLikeClick(
  63. Map<String, dynamic>? data, {
  64. CancelToken? cancelToken,
  65. }) async {
  66. Map<String, dynamic> params = {};
  67. params = data!;
  68. Map<String, String> headers = {};
  69. headers["Content-Type"] = "application/x-www-form-urlencoded";
  70. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  71. final result = await dioEngine.requestNetResult(
  72. // ApiConstants.apiServerTime, // api 地址
  73. '/api/v1/user/property/like/click', // api 地址
  74. params: params,
  75. headers: headers,
  76. method: HttpMethod.POST,
  77. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  78. networkDebounce: true, //是否防抖防止重复请求
  79. cancelToken: cancelToken,
  80. );
  81. Log.d("------请求返回的result--$result--------");
  82. //根据返回的结果,封装原始数据为Bean/Entity对象
  83. if (result.isSuccess) {
  84. //重新赋值data或list
  85. final json = result.getDataJson();
  86. if(json!=null && json['data'] == true){
  87. return result.convert<bool>(data: true);
  88. }else {
  89. return result.convert<bool>(data: false);
  90. }
  91. }else {
  92. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  93. ToastEngine.show("${result.errorMsg}");
  94. }
  95. }
  96. return result.convert();
  97. }
  98. // 获取 transaction 列表 (rent sale)
  99. Future<HttpResult<Object>> fetchTransactionList(
  100. Map<String, dynamic>? data, {
  101. CancelToken? cancelToken,
  102. }) async {
  103. Map<String, dynamic> params = {};
  104. params = data!;
  105. Map<String, String> headers = {};
  106. headers["Content-Type"] = "application/x-www-form-urlencoded";
  107. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  108. final result = await dioEngine.requestNetResult(
  109. // ApiConstants.apiServerTime, // api 地址
  110. '/api/v1/user/property/transaction/list', // api 地址
  111. params: params,
  112. headers: headers,
  113. method: HttpMethod.GET,
  114. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  115. networkDebounce: true, //是否防抖防止重复请求
  116. cancelToken: cancelToken,
  117. );
  118. //根据返回的结果,封装原始数据为Bean/Entity对象
  119. if (result.isSuccess) {
  120. //重新赋值data或list
  121. final json = result.getDataJson();
  122. var data = PropertySaleRentEntity.fromJson(json!);
  123. //重新赋值data或list
  124. return result.convert(data: data);
  125. }else {
  126. if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
  127. ToastEngine.show("${result.errorMsg}");
  128. }
  129. }
  130. return result.convert();
  131. }
  132. }