auth_repository.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import 'package:domain/entity/response/hotel_info_entity.dart';
  2. import 'package:get/get.dart';
  3. import 'package:plugin_platform/dio_export.dart';
  4. import 'package:plugin_platform/http/http_provider.dart';
  5. import 'package:plugin_platform/http/http_result.dart';
  6. import '../constants/api_constants.dart';
  7. /// 用户相关
  8. class AuthRepository extends GetxService {
  9. HttpProvider httpProvider;
  10. AuthRepository({required this.httpProvider});
  11. /// 酒店登录
  12. Future<HttpResult<HotelInfoEntity>> userLogin(
  13. String? email,
  14. String? password, {
  15. CancelToken? cancelToken,
  16. }) async {
  17. //Post请求
  18. Map<String, String> params = {};
  19. params['email'] = email ?? "";
  20. params['password'] = password ?? "";
  21. final result = await httpProvider.requestNetResult(
  22. method: HttpMethod.POST,
  23. ApiConstants.apiUserLogin,
  24. params: params,
  25. networkDebounce: true,
  26. isShowLoadingDialog: true,
  27. cancelToken: cancelToken,
  28. );
  29. //根据返回的结果,封装原始数据为Bean/Entity对象
  30. if (result.isSuccess) {
  31. final json = result.getDataJson();
  32. var data = HotelInfoEntity.fromJson(json!);
  33. //重新赋值data
  34. return result.convert<HotelInfoEntity>(data: data);
  35. }
  36. return result.convert<HotelInfoEntity>();
  37. }
  38. /// 退出登录
  39. Future<HttpResult> userLogout({
  40. CancelToken? cancelToken,
  41. }) async {
  42. final result = await httpProvider.requestNetResult(
  43. ApiConstants.apiUserLogout,
  44. method: HttpMethod.GET,
  45. networkDebounce: true,
  46. isShowLoadingDialog: true,
  47. cancelToken: cancelToken,
  48. );
  49. //根据返回的结果,封装原始数据为Bean/Entity对象
  50. if (result.isSuccess) {
  51. //重新赋值data或list
  52. return result.convert();
  53. }
  54. return result.convert();
  55. }
  56. /// 修改密码
  57. Future<HttpResult> resetPassword(
  58. String? oldPassword,
  59. String? password,
  60. String? confirmPassword, {
  61. CancelToken? cancelToken,
  62. }) async {
  63. Map<String, String> params = {};
  64. params['old_password'] = oldPassword ?? "";
  65. params['password'] = password ?? "";
  66. params['password_confirmation'] = confirmPassword ?? "";
  67. final result = await httpProvider.requestNetResult(
  68. ApiConstants.apiResetPassword,
  69. method: HttpMethod.POST,
  70. params: params,
  71. networkDebounce: true,
  72. isShowLoadingDialog: true,
  73. cancelToken: cancelToken,
  74. );
  75. //根据返回的结果,封装原始数据为Bean/Entity对象
  76. if (result.isSuccess) {
  77. //重新赋值data或list
  78. return result.convert();
  79. }
  80. return result.convert();
  81. }
  82. /// 获取酒店信息
  83. Future<HttpResult<HotelInfoEntity>> fetchHotelInfo() async {
  84. final result = await httpProvider.requestNetResult(
  85. ApiConstants.apiHotelInfo,
  86. );
  87. //根据返回的结果,封装原始数据为Bean/Entity对象
  88. if (result.isSuccess) {
  89. //重新赋值data或list
  90. final json = result.getDataJson();
  91. var data = HotelInfoEntity.fromJson(json!);
  92. //重新赋值data或list
  93. return result.convert<HotelInfoEntity>(data: data);
  94. }
  95. return result.convert();
  96. }
  97. /// 酒店用户注册
  98. Future<HttpResult> hotelRegister(
  99. String? email,
  100. String? password,
  101. String? confirmPassword, {
  102. CancelToken? cancelToken,
  103. }) async {
  104. //参数
  105. Map<String, String> params = {};
  106. params['email'] = email ?? "";
  107. params['password'] = password ?? "";
  108. params['password_confirmation'] = confirmPassword ?? "";
  109. final result = await httpProvider.requestNetResult(
  110. ApiConstants.apiHotelRegister,
  111. method: HttpMethod.POST,
  112. params: params,
  113. networkDebounce: true,
  114. isShowLoadingDialog: true,
  115. cancelToken: cancelToken,
  116. );
  117. //根据返回的结果,封装原始数据为Bean/Entity对象
  118. if (result.isSuccess) {
  119. //重新赋值data或list
  120. return result.convert();
  121. }
  122. return result.convert();
  123. }
  124. /// 酒店用户注销
  125. Future<HttpResult> hotelDeactivate({
  126. CancelToken? cancelToken,
  127. }) async {
  128. final result = await httpProvider.requestNetResult(
  129. ApiConstants.apiHotelDeactivate,
  130. method: HttpMethod.POST,
  131. networkDebounce: true,
  132. isShowLoadingDialog: true,
  133. cancelToken: cancelToken,
  134. );
  135. //根据返回的结果,封装原始数据为Bean/Entity对象
  136. if (result.isSuccess) {
  137. //重新赋值data或list
  138. return result.convert();
  139. }
  140. return result.convert();
  141. }
  142. }