garage_forsale.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import 'package:domain/constants/api_constants.dart';
  2. import 'package:domain/entity/newsfeed_foryou_entity.dart';
  3. import 'package:domain/entity/newsfeed_news_entity.dart';
  4. import 'package:domain/entity/server_time.dart';
  5. import 'package:plugin_platform/platform_export.dart';
  6. import 'package:plugin_platform/http/dio_engine.dart';
  7. import 'package:plugin_platform/http/http_result.dart';
  8. import 'package:riverpod_annotation/riverpod_annotation.dart';
  9. import 'package:shared/utils/log_utils.dart';
  10. import 'package:shared/utils/util.dart';
  11. import 'package:flutter_riverpod/flutter_riverpod.dart';
  12. import 'package:plugin_basic/provider/http_provider/http_provider.dart';
  13. part 'garage_forsale.g.dart';
  14. @Riverpod(keepAlive: true)
  15. GarageForSaleRepository garageForSaleRepository(Ref ref) {
  16. final dioEngine = ref.watch(dioEngineProvider);
  17. return GarageForSaleRepository(dioEngine: dioEngine);
  18. }
  19. /*
  20. * 数据仓库
  21. */
  22. class GarageForSaleRepository {
  23. DioEngine dioEngine;
  24. GarageForSaleRepository({required this.dioEngine});
  25. // news feed - news 列表
  26. Future<HttpResult<Object>> fetchForyouList(
  27. Map<String, dynamic>? data, {
  28. CancelToken? cancelToken,
  29. }) async {
  30. Map<String, dynamic> params = {};
  31. params = data!;
  32. Map<String, String> headers = {};
  33. headers["Content-Type"] = "application/x-www-form-urlencoded";
  34. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  35. final result = await dioEngine.requestNetResult(
  36. // ApiConstants.apiServerTime, // api 地址
  37. '/api/v1/user/news-feed/feed/for-you', // api 地址
  38. params: params,
  39. headers: headers,
  40. method: HttpMethod.GET,
  41. isShowLoadingDialog: false, //是否展示默认的Loading弹窗
  42. networkDebounce: true, //是否防抖防止重复请求
  43. cancelToken: cancelToken,
  44. );
  45. //根据返回的结果,封装原始数据为Bean/Entity对象
  46. if (result.isSuccess) {
  47. //重新赋值data或list
  48. final json = result.getDataJson();
  49. var data = NewsfeedForyouEntity.fromJson(json!);
  50. //重新赋值data或list
  51. return result.convert(data: data);
  52. }
  53. return result.convert();
  54. }
  55. // news feed -news 点赞/取消点赞
  56. Future<HttpResult<Object>> fetchLikeClick(
  57. Map<String, dynamic>? data, {
  58. CancelToken? cancelToken,
  59. }) async {
  60. Map<String, dynamic> params = {};
  61. params = data!;
  62. Map<String, String> headers = {};
  63. headers["Content-Type"] = "application/x-www-form-urlencoded";
  64. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  65. final result = await dioEngine.requestNetResult(
  66. // ApiConstants.apiServerTime, // api 地址
  67. '/api/v1/user/news-feed/like/click', // api 地址
  68. params: params,
  69. headers: headers,
  70. method: HttpMethod.POST,
  71. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  72. networkDebounce: true, //是否防抖防止重复请求
  73. cancelToken: cancelToken,
  74. );
  75. //根据返回的结果,封装原始数据为Bean/Entity对象
  76. if (result.isSuccess) {
  77. //重新赋值data或list
  78. final boolData = result.getDataDynamic();
  79. // var data = NewsfeedForyouEntity.fromJson(json!);
  80. //重新赋值data或list
  81. return result.convert(data: boolData);
  82. }
  83. return result.convert();
  84. }
  85. }