feat: search tackle catalog by name

This commit is contained in:
ik
2026-09-21 19:50:44 +07:00
parent 6fa669b4ef
commit 4d6ec85173
3 changed files with 11 additions and 2 deletions
+5
View File
@@ -44,13 +44,18 @@ def _rig_missing_fields(rig: Rig) -> list[str]:
def tackle_items(
db: Db,
category: str | None = Query(None, pattern="^(bait|lure|rod|reel|line|hook|rig|float|sinker|other)$"),
q: str | None = None,
brand: str | None = None,
family: str | None = None,
unlock_level: int | None = Query(None, ge=0),
limit: int = Query(50, ge=1, le=100),
offset: int = Query(0, ge=0),
) -> PaginatedTackleItemOut:
if q is not None and len(q) > 100:
raise HTTPException(status_code=422, detail="search query is too long")
query = select(TackleItem)
if q and q.strip():
query = query.where(TackleItem.name.ilike(f"%{q.strip()}%"))
if category:
query = query.where(TackleItem.category == category)
if brand: