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>
27 lines
779 B
PHP
27 lines
779 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Api\PredictionRequest;
|
|
use App\Services\NationalFuelPredictionService;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class PredictionController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly NationalFuelPredictionService $predictionService,
|
|
) {}
|
|
|
|
public function index(PredictionRequest $request): JsonResponse
|
|
{
|
|
$fuelType = $request->fuelType();
|
|
$lat = $request->filled('lat') ? (float) $request->input('lat') : null;
|
|
$lng = $request->filled('lng') ? (float) $request->input('lng') : null;
|
|
|
|
$result = $this->predictionService->predict($fuelType, $lat, $lng);
|
|
|
|
return response()->json($result);
|
|
}
|
|
}
|