123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- 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<HttpResult<HotelInfoEntity>> userLogin(
- String? email,
- String? password, {
- CancelToken? cancelToken,
- }) async {
- //Post请求
- Map<String, String> 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<HotelInfoEntity>(data: data);
- }
- return result.convert<HotelInfoEntity>();
- }
- /// 退出登录
- Future<HttpResult> 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<HttpResult> resetPassword(
- String? oldPassword,
- String? password,
- String? confirmPassword, {
- CancelToken? cancelToken,
- }) async {
- Map<String, String> 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<HttpResult<HotelInfoEntity>> 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<HotelInfoEntity>(data: data);
- }
- return result.convert();
- }
- /// 酒店用户注册
- Future<HttpResult> hotelRegister(
- String? email,
- String? password,
- String? confirmPassword, {
- CancelToken? cancelToken,
- }) async {
- //参数
- Map<String, String> 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();
- }
- }
|