feat: FuelPriceService station upsert with tagging
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Station;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
@@ -25,4 +26,44 @@ class FuelPriceService
|
||||
return $response->json('data.access_token');
|
||||
});
|
||||
}
|
||||
|
||||
/** @param array<int, array<string, mixed>> $apiStations */
|
||||
public function upsertStations(array $apiStations): void
|
||||
{
|
||||
$now = now();
|
||||
$rows = [];
|
||||
|
||||
foreach ($apiStations as $data) {
|
||||
$station = new Station([
|
||||
'node_id' => $data['node_id'],
|
||||
'trading_name' => $data['trading_name'],
|
||||
'brand_name' => $data['brand_name'] ?? null,
|
||||
'is_same_trading_and_brand' => $data['is_same_trading_and_brand_name'] ?? false,
|
||||
'is_supermarket' => false,
|
||||
'is_motorway_service_station' => $data['is_motorway_service_station'] ?? false,
|
||||
'is_supermarket_service_station' => $data['is_supermarket_service_station'] ?? false,
|
||||
'temporary_closure' => $data['temporary_closure'] ?? false,
|
||||
'permanent_closure' => $data['permanent_closure'] ?? false,
|
||||
'permanent_closure_date' => $data['permanent_closure_date'] ?? null,
|
||||
'public_phone_number' => $data['public_phone_number'] ?? null,
|
||||
'address_line_1' => $data['location']['address_line_1'] ?? null,
|
||||
'address_line_2' => $data['location']['address_line_2'] ?? null,
|
||||
'city' => $data['location']['city'] ?? null,
|
||||
'county' => $data['location']['county'] ?? null,
|
||||
'country' => $data['location']['country'] ?? null,
|
||||
'postcode' => $data['location']['postcode'],
|
||||
'lat' => $data['location']['latitude'],
|
||||
'lng' => $data['location']['longitude'],
|
||||
'amenities' => $data['amenities'] ?? [],
|
||||
'opening_times' => $data['opening_times'] ?? null,
|
||||
'fuel_types' => $data['fuel_types'] ?? [],
|
||||
'last_seen_at' => $now,
|
||||
]);
|
||||
|
||||
$this->taggingService->tag($station);
|
||||
$rows[] = $station->getAttributes();
|
||||
}
|
||||
|
||||
Station::upsert($rows, ['node_id'], array_keys($rows[0] ?? []));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user