39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from typing import Optional
|
|
|
|
from fastapi import APIRouter, Depends, Header
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.response import success_response
|
|
from app.db import get_db_session
|
|
from app.services.auth_service import AuthService
|
|
from app.services.search_service import SearchService
|
|
|
|
|
|
router = APIRouter(prefix="/search", tags=["search"])
|
|
ROUTE_PERMISSION_SCOPE = "unified_search"
|
|
ROUTE_PERMISSION_ACTIONS = {
|
|
"search": "search:query",
|
|
}
|
|
|
|
|
|
def get_search_service(db: Session = Depends(get_db_session)) -> SearchService:
|
|
return SearchService(db)
|
|
|
|
|
|
def require_current_user(
|
|
authorization: Optional[str] = Header(default=None),
|
|
db: Session = Depends(get_db_session),
|
|
):
|
|
return AuthService(db).require_current_user(authorization)
|
|
|
|
|
|
@router.get("")
|
|
def unified_search(
|
|
q: str,
|
|
types: Optional[str] = None,
|
|
limit: int = 8,
|
|
search_service: SearchService = Depends(get_search_service),
|
|
current_user: dict = Depends(require_current_user),
|
|
):
|
|
return success_response(search_service.search(current_user, q=q, types=types, limit=limit))
|