feat: add GET /api/prediction endpoint
Implements PredictionRequest (fuel_type validation with ValueError→ValidationException), PredictionController delegating to NationalFuelPredictionService, and 5 feature tests. Also fixes LEAST() MySQL-only function to a CASE WHEN expression for SQLite test compatibility. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
33
app/Http/Requests/Api/PredictionRequest.php
Normal file
33
app/Http/Requests/Api/PredictionRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use App\Enums\FuelType;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class PredictionRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'fuel_type' => ['required', 'string'],
|
||||
'lat' => ['nullable', 'numeric', 'between:-90,90'],
|
||||
'lng' => ['nullable', 'numeric', 'between:-180,180'],
|
||||
];
|
||||
}
|
||||
|
||||
public function fuelType(): FuelType
|
||||
{
|
||||
try {
|
||||
return FuelType::fromAlias($this->string('fuel_type')->toString());
|
||||
} catch (\ValueError) {
|
||||
throw ValidationException::withMessages(['fuel_type' => 'Unknown fuel type. Use: diesel, petrol, e10, e5, hvo, b10.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user