Add endpoints: /api/gps/latest-any and /api/gps/recent

This commit is contained in:
2025-08-29 16:22:36 +10:00
parent 6b025255e4
commit bde8fbab81
2 changed files with 33 additions and 2 deletions

View File

@ -9,6 +9,35 @@ use Illuminate\Support\Carbon;
class GpsController extends Controller
{
public function latestAny()
{
$point = \App\Models\GpsPoint::orderByDesc('recorded_at')
->orderByDesc('id')
->first();
if (!$point) {
return response()->json(['message' => 'Not found'], 404);
}
return response()->json($point);
}
public function recent(\Illuminate\Http\Request $req)
{
$limit = (int) $req->input('limit', 50);
$limit = max(1, min($limit, 1000));
$rows = \App\Models\GpsPoint::orderByDesc('recorded_at')
->orderByDesc('id')
->limit($limit)
->get();
return response()->json($rows);
}
// POST /api/gps
public function store(Request $req)
{

View File

@ -8,3 +8,5 @@ Route::get('/health', fn () => response()->json(['ok' => true]));
Route::post('/gps', [GpsController::class, 'store']);
Route::get('/gps/latest', [GpsController::class, 'latest']);
Route::get('/gps/track', [GpsController::class, 'track']);
Route::get('/gps/latest-any', [GpsController::class, 'latestAny']);
Route::get('/gps/recent', [GpsController::class, 'recent']);