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()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user