From bde8fbab81e3b787e9fe8904f55cf90dd2cca592 Mon Sep 17 00:00:00 2001 From: Sam Rolfe Date: Fri, 29 Aug 2025 16:22:36 +1000 Subject: [PATCH] Add endpoints: /api/gps/latest-any and /api/gps/recent --- app/Http/Controllers/GpsController.php | 31 +++++++++++++++++++++++++- routes/api.php | 4 +++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/GpsController.php b/app/Http/Controllers/GpsController.php index f75c625..a835c96 100644 --- a/app/Http/Controllers/GpsController.php +++ b/app/Http/Controllers/GpsController.php @@ -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) { @@ -70,4 +99,4 @@ class GpsController extends Controller $q->orderBy('recorded_at')->orderBy('id')->limit($limit)->get() ); } -} \ No newline at end of file +} diff --git a/routes/api.php b/routes/api.php index ce48b60..52e303b 100644 --- a/routes/api.php +++ b/routes/api.php @@ -7,4 +7,6 @@ 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']); \ No newline at end of file +Route::get('/gps/track', [GpsController::class, 'track']); +Route::get('/gps/latest-any', [GpsController::class, 'latestAny']); +Route::get('/gps/recent', [GpsController::class, 'recent']);