import 'dart:io'; import 'package:ftrecruiter/api/api_provider.dart'; import 'package:ftrecruiter/api/http_result.dart'; import 'package:ftrecruiter/comm/constants/api_constants.dart'; import 'package:ftrecruiter/entity/response/industry_data.dart'; import 'package:ftrecruiter/entity/response/server_time.dart'; import 'package:ftrecruiter/entity/response/user_login.dart'; import 'package:ftrecruiter/entity/response/user_profile.dart'; import 'package:get/get.dart'; class ApiRepository { ApiProvider apiProvider; ApiRepository({required this.apiProvider}); // //获取服务器时间 // void getServerTime({NetSuccessCallback? success, NetErrorCallback? onError}) { // Map headers = {}; // headers["Accept"] = "application/x.yyjobs-api.v1+json"; // // //获取数据和处理数据的逻辑放在这里 // apiProvider.requestNetEasy(ApiConstants.apiServiceTime, headers: headers, onSuccess: (json) { // var serverTime = ServerTime.fromJson(json); // if (success != null) { // success(serverTime); // } // }, onError: onError); // } //获取服务器时间2 Future> getServerTime2() async { Map headers = {}; headers["Accept"] = "application/x.yyjobs-api.v1+json"; //网络请求获取原始数据 final result = await apiProvider.requestNetResult(ApiConstants.apiServiceTime, headers: headers); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { final json = result.getDataJson(); var data = ServerTime.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } /// 获取行业列表 Future> getIndustryList2() async { Map headers = {}; headers["Accept"] = "application/x.yyjobs-api.v1+json"; final result = await apiProvider.requestNetResult(ApiConstants.apiIndustryList, headers: headers); if (result.isSuccess) { final jsonList = result.getListJson(); //获取List数据 需要转换一次 var list = jsonList?.map((value) { if (value is Map) { return IndustryData.fromJson(value); } else { return null; } }).toList(); return result.convert(list: list); } return result.convert(); } //获取用户信息 Future> getUserProfile(String? token) async { Map headers = {}; headers["Accept"] = "application/x.yyjobs-api.v1+json"; headers["Authorization"] = "bearer$token"; var result = await apiProvider.requestNetResult(ApiConstants.apiUserProfile, headers: headers); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { final json = result.getDataJson(); var data = UserProfile.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } //用户登陆 Future> userLogin() async { Map headers = {}; headers["Accept"] = "application/x.yyjobs-api.v1+json"; Map params = {}; params["nric_no"] = "+8618571458165"; params["password"] = "12345678"; params["registration_id"] = "1234"; apiProvider = apiProvider.cancelAndResetHttpClient(); var result = await apiProvider.requestNetResult(ApiConstants.apiUserLogin, method: HttpMethod.POST, headers: headers, query: params); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { final json = result.getDataJson(); var data = UserLogin.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } //更新用户信息 Future> userProfileUpdate(String? token) async { Map headers = {}; headers["Accept"] = "application/x.yyjobs-api.v12+json"; headers["Authorization"] = "bearer$token"; Map params = {}; params["mobile_no"] = "+8618571458166"; params["verification_code"] = "123456 "; params["nick_name"] = "test liukai"; Map paths = {}; paths['news_feed_avatar'] = '/data/user/0/com.hongyegroup.ftrecruiter/app_flutter/test_avatar.jpeg'; var result = await apiProvider.requestNetResult( ApiConstants.apiUpdateProfile, method: HttpMethod.POST, headers: headers, query: params, paths: paths, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { final json = result.getDataJson(); var data = UserLogin.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } //用户登陆(回调的方式) void userLoginEasy({NetSuccessCallback? success, NetErrorCallback? onError}) { Map headers = {}; headers["Accept"] = "application/x.yyjobs-api.v1+json"; Map params = {}; params["nric_no"] = "+8618571458166"; params["password"] = "12345678"; params["registration_id"] = "1234"; apiProvider.requestNetEasy(ApiConstants.apiUserLogin, method: HttpMethod.POST, headers: headers, query: params, onSuccess: (json) { var userLogin = UserLogin.fromJson(json); if (success != null) { success(userLogin); } }, onError: onError); } }