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
|
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
|
// POST /api/gps
|
||||||
public function store(Request $req)
|
public function store(Request $req)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,3 +8,5 @@ Route::get('/health', fn () => response()->json(['ok' => true]));
|
|||||||
Route::post('/gps', [GpsController::class, 'store']);
|
Route::post('/gps', [GpsController::class, 'store']);
|
||||||
Route::get('/gps/latest', [GpsController::class, 'latest']);
|
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