39 lines
1.5 KiB
PHP
39 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Api;
|
|
|
|
use App\Enums\PriceClassification;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class StationResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'station_id' => $this->node_id,
|
|
'name' => $this->trading_name,
|
|
'brand' => $this->brand_name,
|
|
'is_supermarket' => (bool) $this->is_supermarket,
|
|
'address' => implode(', ', array_filter([$this->address_line_1, $this->city])),
|
|
'postcode' => $this->postcode,
|
|
'lat' => (float) $this->lat,
|
|
'lng' => (float) $this->lng,
|
|
'distance_km' => round((float) $this->distance_km, 2),
|
|
'fuel_type' => $this->fuel_type,
|
|
'price_pence' => (int) $this->price_pence,
|
|
'price' => round((int) $this->price_pence / 100, 2),
|
|
'price_updated_at' => $this->price_effective_at
|
|
? Carbon::parse($this->price_effective_at)->toISOString()
|
|
: null,
|
|
'price_classification' => PriceClassification::fromUpdatedAt(
|
|
$this->price_effective_at ? Carbon::parse($this->price_effective_at) : null
|
|
)->value,
|
|
'price_classification_label' => PriceClassification::fromUpdatedAt(
|
|
$this->price_effective_at ? Carbon::parse($this->price_effective_at) : null
|
|
)->label(),
|
|
];
|
|
}
|
|
}
|