23 lines
901 B
Python
Executable File
23 lines
901 B
Python
Executable File
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.orm import Session
|
|
from app.db.session import get_db
|
|
from app.models.vehicle import VehicleBrand # Feltételezve, hogy létezik a modell
|
|
from typing import List
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/search/brands")
|
|
def search_brands(q: str = Query(..., min_length=2), db: Session = Depends(get_db)):
|
|
# 1. KERESÉS A SAJÁT ADATBÁZISBAN
|
|
results = db.query(VehicleBrand).filter(
|
|
VehicleBrand.name.ilike(f"%{q}%"),
|
|
VehicleBrand.is_active == True
|
|
).limit(10).all()
|
|
|
|
# 2. HA NINCS TALÁLAT, INDÍTHATJUK A BOT-OT (Logikai váz)
|
|
if not results:
|
|
# Itt hívnánk meg a Discovery Bot-ot async módon
|
|
# discovery_bot.find_brand_remotely(q)
|
|
return {"status": "not_found", "message": "Nincs találat, a Bot elindult keresni...", "data": []}
|
|
|
|
return {"status": "success", "data": results} |