123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- import 'package:domain/constants/api_constants.dart';
- import 'package:domain/entity/garage_sale_rent_detail_entity.dart';
- import 'package:domain/entity/garage_sale_rent_entity.dart';
- import 'package:domain/entity/myposts_sale_rent_entity.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/engine/toast/toast_engine.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_garage.g.dart';
- @Riverpod(keepAlive: true)
- CommonGarageRespository commonGarageRespository(Ref ref) {
- final dioEngine = ref.watch(dioEngineProvider);
- return CommonGarageRespository(dioEngine: dioEngine);
- }
- /*
- * 数据仓库
- */
- class CommonGarageRespository {
- DioEngine dioEngine;
- CommonGarageRespository({required this.dioEngine});
- // garage 获取 分类 字典
- Future<HttpResult<Object>> fetchGarageCateGoryList(
- Map<String, dynamic>? data, {
- CancelToken? cancelToken,
- }) async {
- Map<String, dynamic> params = {};
- params = data!;
- Map<String, String> 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/garage-sale/category/index', // api 地址
- params: params,
- headers: headers,
- method: HttpMethod.GET,
- 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);
- }else {
- if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
- ToastEngine.show("${result.errorMsg}");
- }
- }
- return result.convert();
- }
- // garage 获取 列表
- Future<HttpResult<Object>> fetchGarageDataList(
- Map<String, dynamic>? data, {
- CancelToken? cancelToken,
- }) async {
- Map<String, dynamic> params = {};
- params = data!;
- Map<String, String> 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/garage-sale/index/type', // api 地址
- params: params,
- headers: headers,
- method: HttpMethod.GET,
- isShowLoadingDialog: false, //是否展示默认的Loading弹窗
- networkDebounce: false, //是否防抖防止重复请求
- cancelToken: cancelToken,
- );
- //根据返回的结果,封装原始数据为Bean/Entity对象
- if (result.isSuccess) {
- //重新赋值data或list
- final json = result.getDataJson();
- var data = GarageSaleRentEntity.fromJson(json!);
- //重新赋值data或list
- return result.convert(data: data);
- }else {
- if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
- ToastEngine.show("${result.errorMsg}");
- }
- }
- return result.convert();
- }
- // myposts 中 garage 获取 列表
- Future<HttpResult<Object>> fetchMyPostsGarageDataList(
- Map<String, dynamic>? data, {
- CancelToken? cancelToken,
- }) async {
- Map<String, dynamic> params = {};
- params = data!;
- Map<String, String> 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: false, //是否防抖防止重复请求
- cancelToken: cancelToken,
- );
- //根据返回的结果,封装原始数据为Bean/Entity对象
- if (result.isSuccess) {
- //重新赋值data或list
- final json = result.getDataJson();
- var data = MypostsSaleRentEntity.fromJson(json!);
- //重新赋值data或list
- return result.convert(data: data);
- }else {
- if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
- ToastEngine.show("${result.errorMsg}");
- }
- }
- return result.convert();
- }
- // garage 点赞/取消点赞
- Future<HttpResult<Object>> fetchGarageColleciton(
- Map<String, dynamic>? data, {
- CancelToken? cancelToken,
- }) async {
- Map<String, dynamic> params = {};
- params = data!;
- Map<String, String> 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/garage-sale/like/click', // 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.getDataDynamic();
- // var data = NewsfeedForyouEntity.fromJson(json!);
- //重新赋值data或list
- return result.convert(data: json);
- }else {
- if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
- ToastEngine.show("${result.errorMsg}");
- }
- }
- return result.convert();
- }
- // 发布 garage
- Future<HttpResult<Object>> fetchPublishGarage(
- Map<String, dynamic>? data, {
- CancelToken? cancelToken,
- }) async {
- Map<String, dynamic> params = {};
- params = data!;
- Map<String, String> headers = {};
- headers["Content-Type"] = "application/x-www-form-urlencoded";
- headers["Accept"] = "application/x.yyjobs-api.v1+json";
- List<String> paths = data!["resources"] as List<String>;
- Map<String, String> files = {};
- if (paths != null && paths.isNotEmpty) {
- paths.asMap().forEach((index, path) {
- files["resources[$index]"] = path;
- });
- }
- // 删除 resources 属性
- params.remove("resources");
- final result = await dioEngine.requestNetResult(
- // ApiConstants.apiServerTime, // api 地址
- '/api/v1/user/garage-sale/index/publish', // api 地址
- params: params,
- paths: files,
- 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);
- }else {
- if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
- ToastEngine.show("${result.errorMsg}");
- }
- }
- return result.convert();
- }
- // 获取 详情信息
- Future<HttpResult<Object>> fetchGarageDetailInfo(
- Map<String, dynamic>? data, {
- CancelToken? cancelToken,
- }) async {
- Map<String, dynamic> params = {};
- params = data!;
- Map<String, String> 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/garage-sale/index/detail', // 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 = GarageSaleRentDetailEntity.fromJson(json!);
- //重新赋值data或list
- return result.convert(data: data);
- }else {
- if(result.errorMsg != null && result.errorMsg!.isNotEmpty){
- ToastEngine.show("${result.errorMsg}");
- }
- }
- return result.convert();
- }
- }
|