chore: أرشفة تطبيقات ولوحات تريبز التي سيحلّ محلها كود سيرو
استكمال قرار 2026-07-27 (كوميت fff76c9 أرشف الباك إند):
apps/rider → apps/rider-archive-cubit
apps/driver → apps/driver-archive-cubit
dashboards/admin-web → dashboards/admin-web-archive
dashboards/service-web → dashboards/service-web-archive
إعادة تسمية بلا تعديل محتوى. rider/driver كانا إعادة بناء Cubit مبنية على
عقد NestJS المؤرشف. admin-web و service-web نموذجان بملف HTML واحد (164 و
128 سطراً) — يحلّ محلهما siro_admin و siro_service المكتملان.
يُحمل من المؤرشف ولا يُعاد اكتشافه: عقد map-saas المثبَّت بالتجربة في
apps/rider-archive-cubit/lib/core/api/ (x-api-key ترويسة، reverse مصفوفة،
route في points) ودرس مسار FCM.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
fff76c949f
commit
9909d9b4c1
@@ -0,0 +1,112 @@
|
||||
import 'package:uuid/uuid.dart';
|
||||
import '../../../core/api/api_client.dart';
|
||||
import 'models/trip_model.dart';
|
||||
import 'models/stop_model.dart';
|
||||
|
||||
const _uuid = Uuid();
|
||||
|
||||
/// مستودع الرحلات — يُستخدم من TripBloc.
|
||||
class TripRepository {
|
||||
final ApiClient _api;
|
||||
TripRepository(this._api);
|
||||
|
||||
/// GET /trips/mine — استرجاع رحلة نشطة.
|
||||
Future<TripModel?> getActiveTrip() async {
|
||||
try {
|
||||
final r = await _api.dio.get('/trips/mine');
|
||||
final data = r.data;
|
||||
if (data == null) return null;
|
||||
final items = (data['items'] ?? data) as List;
|
||||
if (items.isEmpty) return null;
|
||||
final trip = TripModel.fromJson(items.first as Map<String, dynamic>);
|
||||
final active = ['searching', 'assigned', 'driver_arriving', 'driver_arrived', 'in_progress'];
|
||||
if (!active.contains(trip.status)) return null;
|
||||
|
||||
// تصفية: إذا مرت أكثر من 60 دقيقة على إنشاء الرحلة، لا تُعتبر نشطة
|
||||
if (trip.createdAt != null) {
|
||||
final age = DateTime.now().difference(trip.createdAt!);
|
||||
if (age.inMinutes >= 60) return null;
|
||||
}
|
||||
return trip;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// GET /trips/:id — جلب رحلة محددة.
|
||||
Future<TripModel?> getTrip(String tripId) async {
|
||||
try {
|
||||
final r = await _api.dio.get('/trips/$tripId');
|
||||
return TripModel.fromJson(r.data as Map<String, dynamic>);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// POST /trips — إنشاء رحلة جديدة.
|
||||
Future<TripModel> createTrip({
|
||||
required double pickupLat,
|
||||
required double pickupLng,
|
||||
String? pickupAddress,
|
||||
required double dropoffLat,
|
||||
required double dropoffLng,
|
||||
String? dropoffAddress,
|
||||
List<StopModel>? stops,
|
||||
required String vehicleClass,
|
||||
String paymentMethod = 'cash',
|
||||
String? couponCode,
|
||||
String? scheduledAt,
|
||||
}) async {
|
||||
final data = <String, dynamic>{
|
||||
'clientId': _uuid.v4(),
|
||||
'pickup': {
|
||||
'lat': pickupLat,
|
||||
'lng': pickupLng,
|
||||
if (pickupAddress != null) 'address': pickupAddress,
|
||||
},
|
||||
'dropoff': {
|
||||
'lat': dropoffLat,
|
||||
'lng': dropoffLng,
|
||||
if (dropoffAddress != null) 'address': dropoffAddress,
|
||||
},
|
||||
'vehicleClass': vehicleClass,
|
||||
'paymentMethod': paymentMethod,
|
||||
};
|
||||
if (stops != null && stops.isNotEmpty) {
|
||||
data['stops'] = stops.map((s) => s.toJson()).toList();
|
||||
}
|
||||
if (couponCode != null && couponCode.isNotEmpty) {
|
||||
data['couponCode'] = couponCode;
|
||||
}
|
||||
if (scheduledAt != null) data['scheduledAt'] = scheduledAt;
|
||||
|
||||
final r = await _api.dio.post('/trips', data: data);
|
||||
return TripModel.fromJson(r.data as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
/// POST /trips/:id/cancel — إلغاء الرحلة.
|
||||
Future<TripModel> cancelTrip(String tripId) async {
|
||||
final r = await _api.dio.post('/trips/$tripId/cancel');
|
||||
return TripModel.fromJson(r.data as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
/// POST /trips/:id/rate — تقييم الرحلة.
|
||||
Future<void> rateTrip(String tripId, {required int stars, String? comment}) async {
|
||||
await _api.dio.post('/trips/$tripId/rate', data: {
|
||||
'stars': stars,
|
||||
if (comment != null && comment.isNotEmpty) 'comment': comment,
|
||||
});
|
||||
}
|
||||
|
||||
/// GET /trips/rating/pending — هل هناك تقييم معلّق?
|
||||
Future<Map<String, dynamic>?> getPendingRating() async {
|
||||
try {
|
||||
final r = await _api.dio.get('/trips/rating/pending');
|
||||
final data = r.data as Map<String, dynamic>;
|
||||
if (data['pending'] != null) return data;
|
||||
return null;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user