2026-03-29 20:26:30 +08:00
|
|
|
import 'package:social_app/data/network/i_api_client.dart';
|
|
|
|
|
import '../models/signup_request.dart';
|
|
|
|
|
import '../models/login_request.dart';
|
|
|
|
|
import '../models/auth_response.dart';
|
2026-02-25 14:51:21 +08:00
|
|
|
|
|
|
|
|
class AuthApi {
|
2026-03-03 10:12:46 +08:00
|
|
|
final IApiClient _client;
|
2026-02-25 18:00:02 +08:00
|
|
|
static const _prefix = '/api/v1/auth';
|
2026-02-25 14:51:21 +08:00
|
|
|
|
|
|
|
|
AuthApi(this._client);
|
|
|
|
|
|
2026-03-19 18:42:05 +08:00
|
|
|
Future<void> sendOtp(OtpSendRequest request) async {
|
|
|
|
|
await _client.post('$_prefix/otp/send', data: request.toJson());
|
2026-02-25 14:51:21 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 18:42:05 +08:00
|
|
|
Future<AuthResponse> createPhoneSession(LoginRequest request) async {
|
2026-02-25 14:51:21 +08:00
|
|
|
final response = await _client.post(
|
2026-03-19 18:42:05 +08:00
|
|
|
'$_prefix/phone-session',
|
2026-02-25 14:51:21 +08:00
|
|
|
data: request.toJson(),
|
|
|
|
|
);
|
|
|
|
|
return AuthResponse.fromJson(response.data);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 14:28:58 +08:00
|
|
|
Future<AuthResponse> refreshSession(RefreshRequest request) async {
|
2026-02-25 14:51:21 +08:00
|
|
|
final response = await _client.post(
|
2026-02-26 14:28:58 +08:00
|
|
|
'$_prefix/sessions/refresh',
|
2026-02-25 14:51:21 +08:00
|
|
|
data: request.toJson(),
|
|
|
|
|
);
|
|
|
|
|
return AuthResponse.fromJson(response.data);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 14:28:58 +08:00
|
|
|
Future<void> deleteSession(LogoutRequest request) async {
|
|
|
|
|
await _client.delete('$_prefix/sessions', data: request.toJson());
|
2026-02-25 14:51:21 +08:00
|
|
|
}
|
|
|
|
|
}
|