Fix route ordering: /search before /{asset_id}
- /api/assets/search must be registered before /api/assets/{asset_id}
to prevent FastAPI path param from catching 'search' as an asset_id.
Returning a 422 with array detail caused frontend to show [object Object].
- Improve error message extraction in clearAssetGps catch block.
This commit is contained in:
+10
-11
@@ -1586,17 +1586,6 @@ def export_checkins_csv(asset_id: Optional[int] = Query(None)):
|
||||
# ─── Asset GPS Management ──────────────────────────────────────────────────
|
||||
|
||||
|
||||
@app.get("/api/assets/{asset_id}")
|
||||
def get_asset_admin(asset_id: int):
|
||||
"""Get a single asset by ID (admin)."""
|
||||
conn = get_db()
|
||||
row = conn.execute("SELECT * FROM assets WHERE id = ?", (asset_id,)).fetchone()
|
||||
conn.close()
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="Asset not found")
|
||||
return row_to_dict(row)
|
||||
|
||||
|
||||
@app.get("/api/assets/search")
|
||||
def search_assets_admin(machine_id: str = Query(...)):
|
||||
"""Search for an asset by machine_id (admin)."""
|
||||
@@ -1610,6 +1599,16 @@ def search_assets_admin(machine_id: str = Query(...)):
|
||||
return row_to_dict(row)
|
||||
|
||||
|
||||
@app.get("/api/assets/{asset_id}")
|
||||
def get_asset_admin(asset_id: int):
|
||||
"""Get a single asset by ID (admin)."""
|
||||
conn = get_db()
|
||||
row = conn.execute("SELECT * FROM assets WHERE id = ?", (asset_id,)).fetchone()
|
||||
conn.close()
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="Asset not found")
|
||||
return row_to_dict(row)
|
||||
|
||||
@app.delete("/api/assets/{asset_id}/gps", status_code=204)
|
||||
def clear_asset_gps(asset_id: int):
|
||||
"""Clear GPS coordinates from an asset (sets latitude/longitude to NULL)."""
|
||||
|
||||
Reference in New Issue
Block a user