feat: search rig catalog by name
This commit is contained in:
@@ -83,11 +83,19 @@ def tackle_item(item_id: UUID, db: Db) -> TackleItemOut:
|
||||
@router.get("/api/v1/tackle/rigs", response_model=PaginatedRigOut)
|
||||
def tackle_rigs(
|
||||
db: Db,
|
||||
q: str | None = None,
|
||||
limit: int = Query(48, ge=1, le=100),
|
||||
offset: int = Query(0, ge=0),
|
||||
) -> PaginatedRigOut:
|
||||
if q is not None and len(q) > 100:
|
||||
raise HTTPException(status_code=422, detail="search query is too long")
|
||||
query = select(Rig).options(selectinload(Rig.components))
|
||||
total = db.scalar(select(func.count(Rig.id))) or 0
|
||||
if q and q.strip():
|
||||
query = query.where(Rig.name.ilike(f"%{q.strip()}%"))
|
||||
total_query = select(func.count(Rig.id))
|
||||
if q and q.strip():
|
||||
total_query = total_query.where(Rig.name.ilike(f"%{q.strip()}%"))
|
||||
total = db.scalar(total_query) or 0
|
||||
rigs = list(db.scalars(query.order_by(Rig.name, Rig.id).offset(offset).limit(limit)))
|
||||
return PaginatedRigOut(
|
||||
items=[RigSummaryOut(
|
||||
|
||||
Reference in New Issue
Block a user