initial commit
This commit is contained in:
23
app/api/search.py
Normal file
23
app/api/search.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..db import get_db
|
||||
from ..models import Grave
|
||||
from ..schemas import GraveOut
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/", response_model=list[GraveOut])
|
||||
def search_graves(cemetery_id: int, q: str, db: Session = Depends(get_db)):
|
||||
pattern = f"%{q.lower()}%"
|
||||
return (
|
||||
db.query(Grave)
|
||||
.filter(Grave.cemetery_id == cemetery_id)
|
||||
.filter(Grave.full_name.ilike(pattern))
|
||||
.order_by(Grave.id.desc())
|
||||
.all()
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user