58 lines
1.4 KiB
Dart
58 lines
1.4 KiB
Dart
import '../../core/constants/api_endpoints.dart';
|
|
import '../../core/network/api_response.dart';
|
|
import '../../core/network/dio_client.dart';
|
|
import '../models/user.dart';
|
|
|
|
/// 用户服务
|
|
class UserService {
|
|
final DioClient _client;
|
|
|
|
UserService(this._client);
|
|
|
|
/// 用户登录
|
|
Future<ApiResponse<Map<String, dynamic>>> login(
|
|
String username,
|
|
String password,
|
|
) async {
|
|
return _client.post<Map<String, dynamic>>(
|
|
ApiEndpoints.login,
|
|
data: {'username': username, 'password': password},
|
|
);
|
|
}
|
|
|
|
/// 用户注册
|
|
Future<ApiResponse<Map<String, dynamic>>> register(
|
|
String username,
|
|
String password,
|
|
) async {
|
|
return _client.post<Map<String, dynamic>>(
|
|
ApiEndpoints.register,
|
|
data: {'username': username, 'password': password},
|
|
);
|
|
}
|
|
|
|
/// 获取用户信息
|
|
Future<ApiResponse<User>> getUserInfo() async {
|
|
return _client.get<User>(
|
|
ApiEndpoints.userInfo,
|
|
fromJson: (data) => User.fromJson(data as Map<String, dynamic>),
|
|
);
|
|
}
|
|
|
|
/// 上传 KYC 资料
|
|
Future<ApiResponse<void>> uploadKyc(
|
|
String idCardFront,
|
|
String idCardBack,
|
|
) async {
|
|
return _client.post<void>(
|
|
ApiEndpoints.kyc,
|
|
data: {'idCardFront': idCardFront, 'idCardBack': idCardBack},
|
|
);
|
|
}
|
|
|
|
/// 退出登录
|
|
Future<ApiResponse<void>> logout() async {
|
|
return _client.post<void>(ApiEndpoints.logout);
|
|
}
|
|
}
|