- Add PostcodeService to resolve UK postcodes, outcodes, and place names to coordinates via postcodes.io API with 30-day caching - Add LocationResult value object for resolved location data - Add per-fuel-type price validation (80p-1050p range) to FuelPriceService with warning logs for out-of-range prices - Change price_pence column from unsignedSmallInteger to unsignedMediumInteger in station_prices tables - Add CHECK constraints (5000-50000 range) on price_pence columns as database-level guard - Improve error handling in PollFuelPrices command with file/line/trace output - Add tests for PostcodeService covering full postcodes, outcodes, place names, caching, and error handling - Add test for price validation range checks Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Events\PricesUpdatedEvent;
|
|
use App\Services\FuelPriceService;
|
|
use Illuminate\Console\Command;
|
|
use Throwable;
|
|
|
|
class PollFuelPrices extends Command
|
|
{
|
|
protected $signature = 'fuel:poll {--full : Also refresh station metadata}';
|
|
|
|
protected $description = 'Poll the Fuel Finder API for latest prices';
|
|
|
|
public function handle(FuelPriceService $service): int
|
|
{
|
|
$fullRefresh = (bool) $this->option('full');
|
|
|
|
try {
|
|
if ($fullRefresh) {
|
|
$this->info('Refreshing station metadata...');
|
|
$service->refreshStations();
|
|
}
|
|
|
|
$this->info('Polling fuel prices...');
|
|
$inserted = $service->pollPrices();
|
|
|
|
$this->info("Done. $inserted new price record(s) inserted.");
|
|
|
|
PricesUpdatedEvent::dispatch($inserted, $fullRefresh);
|
|
} catch (Throwable $e) {
|
|
$this->error("Poll failed: {$e->getMessage()}");
|
|
$this->error("In {$e->getFile()}:{$e->getLine()}");
|
|
$this->line($e->getTraceAsString());
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|