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,85 @@
|
||||
import '../../../core/api/antlaq_api.dart';
|
||||
import '../../../core/api/api_client.dart';
|
||||
import 'models/place_model.dart';
|
||||
import 'models/route_model.dart';
|
||||
|
||||
/// نقطة وصول وحيدة لبيانات الخرائط والبحث الصوتي الذكي عبر الباك إند.
|
||||
class MapsRepository {
|
||||
final AntlaqApi _api;
|
||||
final ApiClient? _apiClient;
|
||||
|
||||
MapsRepository(this._api, [this._apiClient]);
|
||||
|
||||
/// بحث صوتي ذكي يمر عبر الباك إند (Gemini AI).
|
||||
Future<List<PlaceModel>> voiceSearch(String text, {double? lat, double? lng}) async {
|
||||
if (text.trim().isEmpty) return [];
|
||||
try {
|
||||
if (_apiClient != null) {
|
||||
final res = await _apiClient.dio.post('/maps/voice-search', data: {
|
||||
'text': text,
|
||||
if (lat != null) 'lat': lat,
|
||||
if (lng != null) 'lng': lng,
|
||||
});
|
||||
final list = res.data as List?;
|
||||
if (list != null) {
|
||||
return list
|
||||
.map((e) => PlaceModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
return search(text);
|
||||
}
|
||||
|
||||
/// بحث أماكن — يمر عبر GET /api/geocoding/search.
|
||||
Future<List<PlaceModel>> search(String query) async {
|
||||
if (query.trim().length < 2) return [];
|
||||
final items = await _api.search(query);
|
||||
return items
|
||||
.map((e) => PlaceModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// تفكيك عنوان عكسي (إحداثيات → نص).
|
||||
Future<PlaceModel> reverseGeocode(double lat, double lng) async {
|
||||
final j = await _api.reverse(lat, lng);
|
||||
final name = (j['name_ar'] ?? j['name'] ?? j['formattedAddress'] ?? '') as String;
|
||||
final addr = (j['address'] ?? j['full_address'] ?? j['formattedAddress'] ?? '') as String;
|
||||
return PlaceModel.fromJson({
|
||||
'name': name,
|
||||
'full_address': addr.isNotEmpty ? addr : name,
|
||||
'latitude': lat,
|
||||
'longitude': lng,
|
||||
});
|
||||
}
|
||||
|
||||
/// حساب المسار بين نقطتين عبر الباك إند (GET /maps/route).
|
||||
Future<RouteModel> getRoute({
|
||||
required double fromLat,
|
||||
required double fromLng,
|
||||
required double toLat,
|
||||
required double toLng,
|
||||
}) async {
|
||||
try {
|
||||
if (_apiClient != null) {
|
||||
final res = await _apiClient.dio.get('/maps/route', queryParameters: {
|
||||
'fromLat': fromLat,
|
||||
'fromLng': fromLng,
|
||||
'toLat': toLat,
|
||||
'toLng': toLng,
|
||||
});
|
||||
if (res.data != null && res.data is Map<String, dynamic>) {
|
||||
return RouteModel.fromJson(res.data as Map<String, dynamic>);
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
final j = await _api.route(
|
||||
fromLat: fromLat,
|
||||
fromLng: fromLng,
|
||||
toLat: toLat,
|
||||
toLng: toLng,
|
||||
);
|
||||
return RouteModel.fromJson(j);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
|
||||
/// باب/مدخل مكان — من استجابة انطلق.
|
||||
class Gate extends Equatable {
|
||||
final String nameAr;
|
||||
final String nameEn;
|
||||
final double lat;
|
||||
final double lng;
|
||||
final bool isMainGate;
|
||||
|
||||
const Gate({
|
||||
required this.nameAr,
|
||||
required this.nameEn,
|
||||
required this.lat,
|
||||
required this.lng,
|
||||
this.isMainGate = false,
|
||||
});
|
||||
|
||||
factory Gate.fromJson(Map<String, dynamic> j) => Gate(
|
||||
nameAr: (j['name_ar'] ?? '') as String,
|
||||
nameEn: (j['name_en'] ?? '') as String,
|
||||
lat: (j['latitude'] as num).toDouble(),
|
||||
lng: (j['longitude'] as num).toDouble(),
|
||||
isMainGate: j['is_main_gate'] as bool? ?? false,
|
||||
);
|
||||
|
||||
LatLng get latLng => LatLng(lat, lng);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [nameAr, nameEn, lat, lng, isMainGate];
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'gate_model.dart';
|
||||
|
||||
/// نموذج مكان من نتائج بحث انطلق (geocode / search).
|
||||
class PlaceModel extends Equatable {
|
||||
final String? placeId;
|
||||
final String name;
|
||||
final String? address;
|
||||
final double lat;
|
||||
final double lng;
|
||||
final String? category;
|
||||
final double? totalScore;
|
||||
final String? source;
|
||||
final List<Gate> gates;
|
||||
|
||||
const PlaceModel({
|
||||
this.placeId,
|
||||
required this.name,
|
||||
this.address,
|
||||
required this.lat,
|
||||
required this.lng,
|
||||
this.category,
|
||||
this.totalScore,
|
||||
this.source,
|
||||
this.gates = const [],
|
||||
});
|
||||
|
||||
/// استجابة انطلق الحقيقية — الحقول الم标准.
|
||||
factory PlaceModel.fromJson(Map<String, dynamic> j) {
|
||||
final lat = (j['latitude'] ?? j['location']?['lat'] ?? 0) as num;
|
||||
final lng = (j['longitude'] ?? j['location']?['lng'] ?? 0) as num;
|
||||
return PlaceModel(
|
||||
placeId: j['id'] as String?,
|
||||
name: (j['name'] ?? '') as String,
|
||||
address: (j['full_address'] ?? j['address']) as String?,
|
||||
lat: lat.toDouble(),
|
||||
lng: lng.toDouble(),
|
||||
category: j['category'] as String?,
|
||||
totalScore: (j['totalScore'] as num?)?.toDouble(),
|
||||
source: j['source'] as String?,
|
||||
gates: (j['gates'] as List?)
|
||||
?.map((g) => Gate.fromJson(g as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
const [],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
if (placeId != null) 'id': placeId,
|
||||
'name': name,
|
||||
if (address != null) 'full_address': address,
|
||||
'latitude': lat,
|
||||
'longitude': lng,
|
||||
if (category != null) 'category': category,
|
||||
if (totalScore != null) 'totalScore': totalScore,
|
||||
if (source != null) 'source': source,
|
||||
};
|
||||
|
||||
/// هل لهذا المكان أبواب متعددة?
|
||||
bool get hasMultipleGates => gates.length > 1;
|
||||
|
||||
/// الباب الرئيسي إن وُجد.
|
||||
Gate? get mainGate => gates.cast<Gate?>().firstWhere(
|
||||
(g) => g!.isMainGate,
|
||||
orElse: () => null,
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object?> get props =>
|
||||
[placeId, name, address, lat, lng, category, totalScore, source, gates];
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// فئة رحلة واحدة من الاستجابة (tariff/quote).
|
||||
class QuoteClassModel extends Equatable {
|
||||
final String vehicleClass;
|
||||
final String name;
|
||||
final int price;
|
||||
final String currency;
|
||||
final int capacity;
|
||||
final String? description;
|
||||
final String? imageUrl;
|
||||
final int estimatedTime; // ثوانٍ تقريبية
|
||||
|
||||
const QuoteClassModel({
|
||||
required this.vehicleClass,
|
||||
required this.name,
|
||||
required this.price,
|
||||
required this.currency,
|
||||
required this.capacity,
|
||||
this.description,
|
||||
this.imageUrl,
|
||||
required this.estimatedTime,
|
||||
});
|
||||
|
||||
factory QuoteClassModel.fromJson(Map<String, dynamic> j) => QuoteClassModel(
|
||||
vehicleClass: j['vehicleClass'] as String,
|
||||
name: (j['name'] ?? j['vehicleClass']) as String,
|
||||
price: j['price'] as int,
|
||||
currency: (j['currency'] ?? 'JOD') as String,
|
||||
capacity: j['capacity'] as int? ?? 4,
|
||||
description: j['description'] as String?,
|
||||
imageUrl: j['imageUrl'] as String?,
|
||||
estimatedTime: j['estimatedTime'] as int? ?? 0,
|
||||
);
|
||||
|
||||
String get estimatedTimeText {
|
||||
final min = estimatedTime ~/ 60;
|
||||
return '$min min';
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [vehicleClass, name, price, currency, capacity];
|
||||
}
|
||||
|
||||
/// استجابة tariff/quote الكاملة.
|
||||
class QuoteModel extends Equatable {
|
||||
final String? pickupAddress;
|
||||
final String? dropoffAddress;
|
||||
final int distanceMeters;
|
||||
final int durationSeconds;
|
||||
final String? distanceText;
|
||||
final String? durationText;
|
||||
final String currency;
|
||||
final List<QuoteClassModel> classes;
|
||||
|
||||
const QuoteModel({
|
||||
this.pickupAddress,
|
||||
this.dropoffAddress,
|
||||
required this.distanceMeters,
|
||||
required this.durationSeconds,
|
||||
this.distanceText,
|
||||
this.durationText,
|
||||
required this.currency,
|
||||
required this.classes,
|
||||
});
|
||||
|
||||
factory QuoteModel.fromJson(Map<String, dynamic> j) {
|
||||
final data = j['data'] ?? j;
|
||||
return QuoteModel(
|
||||
pickupAddress: data['pickupAddress'] as String?,
|
||||
dropoffAddress: data['dropoffAddress'] as String?,
|
||||
distanceMeters: (data['distanceMeters'] as num?)?.toInt() ?? 0,
|
||||
durationSeconds: (data['durationSeconds'] as num?)?.toInt() ?? 0,
|
||||
distanceText: data['distanceText'] as String?,
|
||||
durationText: data['durationText'] as String?,
|
||||
currency: (data['currency'] ?? 'JOD') as String,
|
||||
classes: (data['classes'] as List? ?? [])
|
||||
.map((c) => QuoteClassModel.fromJson(c as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [distanceMeters, durationSeconds, currency, classes];
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// فئة رحلة من ride-types endpoint (تُستخدم كقائمة المرجع).
|
||||
class RideTypeModel extends Equatable {
|
||||
final String id;
|
||||
final String name;
|
||||
final String? vehicleClass;
|
||||
final int capacity;
|
||||
final String? description;
|
||||
final String? imageUrl;
|
||||
final bool active;
|
||||
|
||||
const RideTypeModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
this.vehicleClass,
|
||||
required this.capacity,
|
||||
this.description,
|
||||
this.imageUrl,
|
||||
required this.active,
|
||||
});
|
||||
|
||||
factory RideTypeModel.fromJson(Map<String, dynamic> j) => RideTypeModel(
|
||||
id: j['id'] as String,
|
||||
name: (j['name'] ?? '') as String,
|
||||
vehicleClass: j['vehicleClass'] as String?,
|
||||
capacity: j['capacity'] as int? ?? 4,
|
||||
description: j['description'] as String?,
|
||||
imageUrl: j['imageUrl'] as String?,
|
||||
active: j['active'] as bool? ?? true,
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, name, vehicleClass, capacity, active];
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
|
||||
/// استجابة مسار من انطلق — مع polyline مشفر وإطار خريطة.
|
||||
class RouteModel extends Equatable {
|
||||
final int distanceMeters;
|
||||
final int durationSeconds;
|
||||
final String? polyline;
|
||||
final String? routeName;
|
||||
final String? startName;
|
||||
final String? endName;
|
||||
final List<String>? tags;
|
||||
final List<double>? bbox;
|
||||
final double? trafficFactor;
|
||||
|
||||
const RouteModel({
|
||||
required this.distanceMeters,
|
||||
required this.durationSeconds,
|
||||
this.polyline,
|
||||
this.routeName,
|
||||
this.startName,
|
||||
this.endName,
|
||||
this.tags,
|
||||
this.bbox,
|
||||
this.trafficFactor,
|
||||
});
|
||||
|
||||
/// استجابة مسار انطلق الحقيقية (تُمرر عبر الباك إند كما هي).
|
||||
factory RouteModel.fromJson(Map<String, dynamic> j) {
|
||||
final dist = (j['distance'] ?? 0) as num;
|
||||
final dur = (j['duration'] ?? 0) as num;
|
||||
return RouteModel(
|
||||
distanceMeters: dist.toInt(),
|
||||
durationSeconds: dur.toInt(),
|
||||
polyline: j['points'] as String?,
|
||||
routeName: j['routeName'] as String?,
|
||||
startName: j['startName'] as String?,
|
||||
endName: j['endName'] as String?,
|
||||
tags: (j['tags'] as List?)?.cast<String>(),
|
||||
bbox: (j['bbox'] as List?)?.map((e) => (e as num).toDouble()).toList(),
|
||||
trafficFactor: (j['trafficFactor'] as num?)?.toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
String get distanceText {
|
||||
if (distanceMeters < 1000) return '$distanceMeters m';
|
||||
return '${(distanceMeters / 1000).toStringAsFixed(1)} km';
|
||||
}
|
||||
|
||||
String get durationText {
|
||||
final min = durationSeconds ~/ 60;
|
||||
if (min < 60) return '$min min';
|
||||
final h = min ~/ 60;
|
||||
final rem = min % 60;
|
||||
return '$h h ${rem > 0 ? '$rem min' : ''}';
|
||||
}
|
||||
|
||||
/// تحويل bbox إلى LatLngBounds لضبط الكاميرا مع حماية للمواقع القريبة على iOS.
|
||||
LatLngBounds? getLatLngBounds() {
|
||||
if (bbox == null || bbox!.length < 4) return null;
|
||||
var minLat = bbox![1];
|
||||
var minLng = bbox![0];
|
||||
var maxLat = bbox![3];
|
||||
var maxLng = bbox![2];
|
||||
|
||||
// إذا كانت المسافة بين النقاط قريبة جداً (أقل من 0.002 درجة)، نضمن توسعاً أمنياً أدنى لمنع عطل وقفل كاميرا MapLibre على iOS
|
||||
if ((maxLat - minLat).abs() < 0.002) {
|
||||
minLat -= 0.001;
|
||||
maxLat += 0.001;
|
||||
}
|
||||
if ((maxLng - minLng).abs() < 0.002) {
|
||||
minLng -= 0.001;
|
||||
maxLng += 0.001;
|
||||
}
|
||||
|
||||
return LatLngBounds(
|
||||
southwest: LatLng(minLat, minLng),
|
||||
northeast: LatLng(maxLat, maxLng),
|
||||
);
|
||||
}
|
||||
|
||||
/// فك الـ polyline عبر PolylineUtils من الباكيج.
|
||||
List<LatLng> decodePolyline() {
|
||||
if (polyline == null || polyline!.isEmpty) return [];
|
||||
return PolylineUtils.decode(polyline!);
|
||||
}
|
||||
|
||||
/// هل المسار مباشر (لا أضلاع)?
|
||||
bool get isStraightLine => tags?.contains('straight-line') ?? false;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
distanceMeters,
|
||||
durationSeconds,
|
||||
polyline,
|
||||
routeName,
|
||||
startName,
|
||||
endName,
|
||||
tags,
|
||||
bbox,
|
||||
trafficFactor,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// نقطة توقف أثناء الرحلة.
|
||||
class StopModel extends Equatable {
|
||||
final double lat;
|
||||
final double lng;
|
||||
final String? label;
|
||||
final String? address;
|
||||
|
||||
const StopModel({
|
||||
required this.lat,
|
||||
required this.lng,
|
||||
this.label,
|
||||
this.address,
|
||||
});
|
||||
|
||||
factory StopModel.fromJson(Map<String, dynamic> j) => StopModel(
|
||||
lat: (j['lat'] as num).toDouble(),
|
||||
lng: (j['lng'] as num).toDouble(),
|
||||
label: j['label'] as String?,
|
||||
address: j['address'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'lat': lat,
|
||||
'lng': lng,
|
||||
if (label != null) 'label': label,
|
||||
if (address != null) 'address': address,
|
||||
};
|
||||
|
||||
@override
|
||||
List<Object?> get props => [lat, lng, label, address];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import '../../../core/api/api_client.dart';
|
||||
import 'models/ride_type_model.dart';
|
||||
|
||||
/// جلب فئات الرحلة المتاحة من المستأجر.
|
||||
class RideTypesRepository {
|
||||
final ApiClient _api;
|
||||
RideTypesRepository(this._api);
|
||||
|
||||
/// GET /ride-types — تُستخدم كمرجع للفئات النشطة.
|
||||
Future<List<RideTypeModel>> getRideTypes() async {
|
||||
final r = await _api.dio.get('/ride-types');
|
||||
final items = (r.data['items'] ?? r.data ?? []) as List;
|
||||
return items
|
||||
.map((e) => RideTypeModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import '../../../core/api/api_client.dart';
|
||||
import 'models/quote_model.dart';
|
||||
import 'models/stop_model.dart';
|
||||
|
||||
/// استخراج الأسعار لكل فئة رحلة.
|
||||
class TariffRepository {
|
||||
final ApiClient _api;
|
||||
TariffRepository(this._api);
|
||||
|
||||
/// جلب عرض أسعار للمسار المحدد — POST /tariff/quote.
|
||||
///
|
||||
/// الاستجابة تحتوي `classes[]` بسعر لكل فئة مع breakdown.
|
||||
Future<QuoteModel> getQuote({
|
||||
required double pickupLat,
|
||||
required double pickupLng,
|
||||
required String? pickupAddress,
|
||||
required double dropoffLat,
|
||||
required double dropoffLng,
|
||||
required String? dropoffAddress,
|
||||
List<StopModel>? stops,
|
||||
String? vehicleClass,
|
||||
String? scheduledAt,
|
||||
}) async {
|
||||
final data = <String, dynamic>{
|
||||
'pickup': {
|
||||
'lat': pickupLat,
|
||||
'lng': pickupLng,
|
||||
if (pickupAddress != null) 'address': pickupAddress,
|
||||
},
|
||||
'dropoff': {
|
||||
'lat': dropoffLat,
|
||||
'lng': dropoffLng,
|
||||
if (dropoffAddress != null) 'address': dropoffAddress,
|
||||
},
|
||||
};
|
||||
if (stops != null && stops.isNotEmpty) {
|
||||
data['stops'] = stops.nonNulls.map((s) => s.toJson()).toList();
|
||||
}
|
||||
if (vehicleClass != null) data['vehicleClass'] = vehicleClass;
|
||||
if (scheduledAt != null) data['scheduledAt'] = scheduledAt;
|
||||
|
||||
final r = await _api.dio.post('/tariff/quote', data: data);
|
||||
return QuoteModel.fromJson(r.data as Map<String, dynamic>);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user