newsfeed_detail_repository.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import 'package:domain/constants/api_constants.dart';
  2. import 'package:domain/entity/newsfeed_comment_publish_entity.dart';
  3. import 'package:domain/entity/newsfeed_detail_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 'newsfeed_detail_repository.g.dart';
  15. @Riverpod(keepAlive: true)
  16. NewsFeedDetailRepository newsFeedDetailRepository(Ref ref) {
  17. final dioEngine = ref.watch(dioEngineProvider);
  18. return NewsFeedDetailRepository(dioEngine: dioEngine);
  19. }
  20. /*
  21. * 数据仓库
  22. */
  23. class NewsFeedDetailRepository {
  24. DioEngine dioEngine;
  25. NewsFeedDetailRepository({required this.dioEngine});
  26. // 获取 详情信息
  27. Future<HttpResult<Object>> fetchNewsFeedDetailInfo(
  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/news-feed/feed/detail', // api 地址
  39. params: params,
  40. headers: headers,
  41. method: HttpMethod.GET,
  42. isShowLoadingDialog: false, //是否展示默认的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 = NewsfeedDetailEntity.fromJson(json!);
  51. //重新赋值data或list
  52. return result.convert(data: data);
  53. }
  54. return result.convert();
  55. }
  56. // 提交评论
  57. Future<HttpResult<Object>> fetchNewsfeedCommentSubmit(
  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/news-feed/comment/publish', // api 地址
  69. params: params,
  70. headers: headers,
  71. method: HttpMethod.POST,
  72. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  73. networkDebounce: true, //是否防抖防止重复请求
  74. cancelToken: cancelToken,
  75. );
  76. //根据返回的结果,封装原始数据为Bean/Entity对象
  77. if (result.isSuccess) {
  78. //重新赋值data或list
  79. final json = result.getDataJson();
  80. var data = NewsfeedCommentPublishEntity.fromJson(json!);
  81. //重新赋值data或list
  82. return result.convert(data: data);
  83. }
  84. return result.convert();
  85. }
  86. }