26 lines
912 B
Python
26 lines
912 B
Python
"""Search endpoint (section 16, section 17)."""
|
|||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from fastapi import APIRouter, Depends, Query
|
||
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
|
|
||
|
|
from app.core.database import get_db
|
||
|
|
from app.core.security import enforce_rate_limit
|
||
|
|
from app.schemas.search import SearchResultsOut
|
||
|
|
from app.services.search.postgresql_provider import PostgreSQLSearchProvider
|
||
|
|
from app.services.search.service import SearchService
|
||
|
|
|
||
|
|
router = APIRouter(prefix="/search", tags=["search"], dependencies=[Depends(enforce_rate_limit)])
|
||
|
|
|
||
|
|
_search_service = SearchService(PostgreSQLSearchProvider())
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("", response_model=SearchResultsOut)
|
||
|
|
async def search(
|
||
|
|
q: str = Query(..., min_length=1, max_length=300),
|
||
|
|
limit: int = Query(10, ge=1, le=50),
|
||
|
|
session: AsyncSession = Depends(get_db),
|
||
|
|
) -> SearchResultsOut:
|
||
|
|
return await _search_service.search(session, q, limit_per_type=limit)
|