Files
tripz-llc/apps/driver/lib/features/home/data/driver_repository.dart
T

51 lines
1.5 KiB
Dart

import '../../../core/api/api_client.dart';
import 'models/driver_profile_model.dart';
/// مستودع بيانات السائق — يُستخدم من DriverCubit.
class DriverRepository {
final ApiClient _api;
DriverRepository(this._api);
/// `GET /drivers/me` — جلب ملف السائق.
Future<DriverProfileModel?> getProfile() async {
try {
final r = await _api.dio.get('/drivers/me');
return DriverProfileModel.fromJson(r.data as Map<String, dynamic>);
} catch (_) {
return null;
}
}
/// `PATCH /drivers/status` — تبديل الحالة (مُتصل/مُنقطع).
Future<bool> setOnline(bool online) async {
try {
final r = await _api.dio.patch('/drivers/status', data: {'online': online});
return r.data['online'] as bool? ?? online;
} catch (_) {
return false;
}
}
/// `POST /drivers/location` — إرسال الموقع الحالي.
///
/// يُعيد `true` إذا كان الموقع "مُهماً" (تغيير كبير حسب السيرفر).
Future<bool> sendLocation({
required double lat,
required double lng,
double? heading,
double? speed,
}) async {
try {
final r = await _api.dio.post('/drivers/location', data: {
'lat': lat,
'lng': lng,
if (heading != null) 'heading': heading,
if (speed != null) 'speed': speed,
});
return r.data['significant'] as bool? ?? false;
} catch (_) {
return false;
}
}
}