auth_repository.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:get/get.dart';
  2. import 'package:plugin_platform/http/http_provider.dart';
  3. import 'package:plugin_platform/http/http_result.dart';
  4. import '../constants/api_constants.dart';
  5. import '../entity/response/user_profile.dart';
  6. import '../entity/response/verify_code.dart';
  7. /// 用户相关
  8. class AuthRepository extends GetxService {
  9. HttpProvider httpProvider;
  10. AuthRepository({required this.httpProvider});
  11. /// 获取发送验证码的图片,用于发送短信
  12. Future<HttpResult<VerifyCode>> getVerifyCodeImage() async {
  13. //Get请求
  14. final result = await httpProvider.requestNetResult(ApiConstants.apiVerifyCodeImage);
  15. //根据返回的结果,封装原始数据为Bean/Entity对象
  16. if (result.isSuccess) {
  17. final json = result.getDataJson();
  18. var data = VerifyCode.fromJson(json!);
  19. //重新赋值data或list
  20. return result.convert<VerifyCode>(data: data);
  21. }
  22. return result.convert<VerifyCode>();
  23. }
  24. /// 获取用户详情数据
  25. Future<HttpResult<UserProfile>> fetchUserProfile() async {
  26. //POST请求
  27. final result = await httpProvider.requestNetResult(
  28. ApiConstants.apiUserProfile,
  29. );
  30. //根据返回的结果,封装原始数据为Bean/Entity对象
  31. if (result.isSuccess) {
  32. //重新赋值data或list
  33. final json = result.getDataJson();
  34. var data = UserProfile.fromJson(json!);
  35. //重新赋值data或list
  36. return result.convert<UserProfile>(data: data);
  37. }
  38. return result.convert();
  39. }
  40. }