import 'package:domain/constants/api_constants.dart'; import 'package:domain/entity/newsfeed_foryou_entity.dart'; import 'package:domain/entity/newsfeed_news_entity.dart'; import 'package:domain/entity/server_time.dart'; import 'package:plugin_platform/platform_export.dart'; import 'package:plugin_platform/http/dio_engine.dart'; import 'package:plugin_platform/http/http_result.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:shared/utils/log_utils.dart'; import 'package:shared/utils/util.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:plugin_basic/provider/http_provider/http_provider.dart'; part 'common_newsfeed.g.dart'; @Riverpod(keepAlive: true) CommonNewsFeedRepository commonNewsFeedRepository(Ref ref) { final dioEngine = ref.watch(dioEngineProvider); return CommonNewsFeedRepository(dioEngine: dioEngine); } /* * 数据仓库 */ class CommonNewsFeedRepository { DioEngine dioEngine; CommonNewsFeedRepository({required this.dioEngine}); // 获取 我关注的人 Future> fetchMyFollowList( Map? data, { CancelToken? cancelToken, }) async { Map params = {}; params = data!; Map headers = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; headers["Accept"] = "application/x.yyjobs-api.v1+json"; final result = await dioEngine.requestNetResult( // ApiConstants.apiServerTime, // api 地址 '/api/v1/user/me/index/follows', // api 地址 params: params, headers: headers, method: HttpMethod.GET, isShowLoadingDialog: false, //是否展示默认的Loading弹窗 networkDebounce: true, //是否防抖防止重复请求 cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); // var data = NewsfeedForyouEntity.fromJson(json!); //重新赋值data或list return result.convert(data: json); } return result.convert(); } // 获取 关注我的人 Future> fetchMyFollowerList( Map? data, { CancelToken? cancelToken, }) async { Map params = {}; params = data!; Map headers = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; headers["Accept"] = "application/x.yyjobs-api.v1+json"; final result = await dioEngine.requestNetResult( // ApiConstants.apiServerTime, // api 地址 '/api/v1/user/me/index/flowers', // api 地址 params: params, headers: headers, method: HttpMethod.GET, isShowLoadingDialog: false, //是否展示默认的Loading弹窗 networkDebounce: true, //是否防抖防止重复请求 cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); // var data = NewsfeedForyouEntity.fromJson(json!); //重新赋值data或list return result.convert(data: json); } return result.convert(); } // 关注/取消关注 Future> handlerFollowOrCancel( Map? data, { CancelToken? cancelToken, }) async { Map params = {}; params = data!; Map headers = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; headers["Accept"] = "application/x.yyjobs-api.v1+json"; final result = await dioEngine.requestNetResult( // ApiConstants.apiServerTime, // api 地址 '/api/v1/user/me/index/follow', // api 地址 params: params, headers: headers, method: HttpMethod.POST, isShowLoadingDialog: true, //是否展示默认的Loading弹窗 networkDebounce: true, //是否防抖防止重复请求 cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); // var data = NewsfeedForyouEntity.fromJson(json!); //重新赋值data或list return result.convert(data: json); } return result.convert(); } // 获取 我发布的newsfeed Future> fetchMyPostNewsfeedList( Map? data, { CancelToken? cancelToken, }) async { Map params = {}; params = data!; Map headers = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; headers["Accept"] = "application/x.yyjobs-api.v1+json"; final result = await dioEngine.requestNetResult( // ApiConstants.apiServerTime, // api 地址 '/api/v1/user/me/post/news-feed', // api 地址 params: params, headers: headers, method: HttpMethod.GET, isShowLoadingDialog: false, //是否展示默认的Loading弹窗 networkDebounce: true, //是否防抖防止重复请求 cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); // var data = NewsfeedDetailEntity.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } // 获取 我发布的 garage Future> fetchMyPostGarageList( Map? data, { CancelToken? cancelToken, }) async { Map params = {}; params = data!; Map headers = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; headers["Accept"] = "application/x.yyjobs-api.v1+json"; final result = await dioEngine.requestNetResult( // ApiConstants.apiServerTime, // api 地址 '/api/v1/user/me/post/garage-sale', // api 地址 params: params, headers: headers, method: HttpMethod.GET, isShowLoadingDialog: false, //是否展示默认的Loading弹窗 networkDebounce: true, //是否防抖防止重复请求 cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); // var data = NewsfeedDetailEntity.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } }