migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Modules\RestaurantDelivery\Models\Delivery;
|
||||
|
||||
class DeliveryTrackingResource extends JsonResource
|
||||
{
|
||||
protected ?array $trackingData;
|
||||
|
||||
public function __construct(Delivery $delivery, ?array $trackingData = null)
|
||||
{
|
||||
parent::__construct($delivery);
|
||||
$this->trackingData = $trackingData;
|
||||
}
|
||||
|
||||
public function toArray($request): array
|
||||
{
|
||||
$delivery = $this->resource;
|
||||
|
||||
return [
|
||||
'tracking_code' => $delivery->tracking_code,
|
||||
|
||||
// Status
|
||||
'status' => [
|
||||
'code' => $delivery->status->value,
|
||||
'label' => $delivery->status->label(),
|
||||
'description' => $delivery->status->description(),
|
||||
'color' => $delivery->status->color(),
|
||||
'icon' => $delivery->status->icon(),
|
||||
],
|
||||
|
||||
// Restaurant location
|
||||
'restaurant' => [
|
||||
'name' => $delivery->restaurant_name,
|
||||
'address' => $delivery->pickup_address,
|
||||
'latitude' => (float) $delivery->pickup_latitude,
|
||||
'longitude' => (float) $delivery->pickup_longitude,
|
||||
],
|
||||
|
||||
// Customer location
|
||||
'customer' => [
|
||||
'address' => $delivery->drop_address,
|
||||
'latitude' => (float) $delivery->drop_latitude,
|
||||
'longitude' => (float) $delivery->drop_longitude,
|
||||
],
|
||||
|
||||
// Rider info
|
||||
'rider' => $delivery->rider ? [
|
||||
'id' => $delivery->rider->uuid,
|
||||
'name' => $delivery->rider->full_name,
|
||||
'phone' => $delivery->rider->phone,
|
||||
'photo' => $delivery->rider->photo_url,
|
||||
'rating' => (float) $delivery->rider->rating,
|
||||
'rating_count' => $delivery->rider->rating_count,
|
||||
'vehicle_type' => $delivery->rider->vehicle_type->value,
|
||||
'vehicle_number' => $delivery->rider->vehicle_number,
|
||||
] : null,
|
||||
|
||||
// Live tracking data
|
||||
'tracking' => $this->trackingData ? [
|
||||
'rider_location' => $this->trackingData['rider_location'] ?? null,
|
||||
'route' => $this->trackingData['route'] ?? null,
|
||||
'eta' => $this->trackingData['eta'] ?? null,
|
||||
'remaining_distance' => $this->trackingData['remaining_distance'] ?? null,
|
||||
'animation' => $this->trackingData['animation'] ?? null,
|
||||
] : null,
|
||||
|
||||
// Estimated times
|
||||
'estimated_pickup' => $delivery->estimated_pickup_time?->format('H:i'),
|
||||
'estimated_delivery' => $delivery->estimated_delivery_time?->format('H:i'),
|
||||
|
||||
// Distance
|
||||
'distance' => [
|
||||
'total' => (float) $delivery->distance,
|
||||
'unit' => $delivery->distance_unit,
|
||||
],
|
||||
|
||||
// Map config
|
||||
'map_config' => [
|
||||
'default_zoom' => config('restaurant-delivery.tracking.map.default_zoom'),
|
||||
'tracking_zoom' => config('restaurant-delivery.tracking.map.tracking_zoom'),
|
||||
'auto_center' => config('restaurant-delivery.tracking.map.auto_center'),
|
||||
'show_route' => config('restaurant-delivery.tracking.map.show_route_polyline'),
|
||||
'show_eta' => config('restaurant-delivery.tracking.map.show_eta'),
|
||||
],
|
||||
|
||||
// Markers config
|
||||
'markers' => config('restaurant-delivery.tracking.markers'),
|
||||
|
||||
// Polyline config
|
||||
'polyline' => config('restaurant-delivery.tracking.polyline'),
|
||||
|
||||
// Animation config
|
||||
'animation' => config('restaurant-delivery.tracking.animation'),
|
||||
|
||||
// Firebase config for client
|
||||
'firebase_config' => [
|
||||
'path' => "deliveries/{$delivery->id}/tracking",
|
||||
'enabled' => config('restaurant-delivery.firebase.enabled'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user