- Split mother's name in KYC (last/first) - Added mileage_unit and fuel_type to Assets - Expanded AssetCost for international VAT and original currency - Fixed SQLAlchemy IndexError in asset catalog lookup - Added exchange_rate and ratings tables to models
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy import select, or_
|
|
from app.db.session import get_db
|
|
from app.models import AssetCatalog
|
|
from typing import List
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/search")
|
|
async def search_catalog(
|
|
q: str = Query(..., min_length=2, description="Márka vagy típus keresése"),
|
|
category: str = None,
|
|
db: AsyncSession = Depends(get_db)
|
|
):
|
|
"""Keresés a Robot által feltöltött katalógusban."""
|
|
stmt = select(VehicleCatalog).where(
|
|
or_(
|
|
VehicleCatalog.brand.ilike(f"%{q}%"),
|
|
VehicleCatalog.model.ilike(f"%{q}%")
|
|
)
|
|
)
|
|
if category:
|
|
stmt = stmt.where(VehicleCatalog.category == category)
|
|
|
|
result = await db.execute(stmt.limit(20))
|
|
items = result.scalars().all()
|
|
|
|
return [
|
|
{
|
|
"id": i.id,
|
|
"full_name": f"{i.brand} {i.model}",
|
|
"category": i.category,
|
|
"status": i.verification_status,
|
|
"specs": i.factory_specs
|
|
} for i in items
|
|
] |