Add endpoints: /api/gps/latest-any and /api/gps/recent
This commit is contained in:
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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']);
|
||||
Route::get('/gps/track', [GpsController::class, 'track']);
|
||||
Route::get('/gps/latest-any', [GpsController::class, 'latestAny']);
|
||||
Route::get('/gps/recent', [GpsController::class, 'recent']);
|
||||
|
||||
Reference in New Issue
Block a user