import 'package:domain/entity/response/hotel_info_entity.dart'; import 'package:get/get.dart'; import 'package:plugin_platform/dio_export.dart'; import 'package:plugin_platform/http/http_provider.dart'; import 'package:plugin_platform/http/http_result.dart'; import '../constants/api_constants.dart'; /// 用户相关 class AuthRepository extends GetxService { HttpProvider httpProvider; AuthRepository({required this.httpProvider}); /// 酒店登录 Future> userLogin( String? email, String? password, { CancelToken? cancelToken, }) async { //Post请求 Map params = {}; params['email'] = email ?? ""; params['password'] = password ?? ""; final result = await httpProvider.requestNetResult( method: HttpMethod.POST, ApiConstants.apiUserLogin, params: params, networkDebounce: true, isShowLoadingDialog: true, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { final json = result.getDataJson(); var data = HotelInfoEntity.fromJson(json!); //重新赋值data return result.convert(data: data); } return result.convert(); } /// 退出登录 Future userLogout({ CancelToken? cancelToken, }) async { final result = await httpProvider.requestNetResult( ApiConstants.apiUserLogout, method: HttpMethod.GET, networkDebounce: true, isShowLoadingDialog: true, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list return result.convert(); } return result.convert(); } /// 修改密码 Future resetPassword( String? oldPassword, String? password, String? confirmPassword, { CancelToken? cancelToken, }) async { Map params = {}; params['old_password'] = oldPassword ?? ""; params['password'] = password ?? ""; params['password_confirmation'] = confirmPassword ?? ""; final result = await httpProvider.requestNetResult( ApiConstants.apiResetPassword, method: HttpMethod.POST, params: params, networkDebounce: true, isShowLoadingDialog: true, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list return result.convert(); } return result.convert(); } /// 获取酒店信息 Future> fetchHotelInfo() async { final result = await httpProvider.requestNetResult( ApiConstants.apiHotelInfo, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list final json = result.getDataJson(); var data = HotelInfoEntity.fromJson(json!); //重新赋值data或list return result.convert(data: data); } return result.convert(); } /// 酒店用户注册 Future hotelRegister( String? email, String? password, String? confirmPassword, { CancelToken? cancelToken, }) async { //参数 Map params = {}; params['email'] = email ?? ""; params['password'] = password ?? ""; params['password_confirmation'] = confirmPassword ?? ""; final result = await httpProvider.requestNetResult( ApiConstants.apiHotelRegister, method: HttpMethod.POST, params: params, networkDebounce: true, isShowLoadingDialog: true, cancelToken: cancelToken, ); //根据返回的结果,封装原始数据为Bean/Entity对象 if (result.isSuccess) { //重新赋值data或list return result.convert(); } return result.convert(); } }