Feature: Guestbook phone autosearch also searches names.
This commit is contained in:
parent
78dcd6b92a
commit
91451eebc9
@ -5,6 +5,7 @@ from typing import List
|
||||
import barker.schemas.customer as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@ -127,10 +128,13 @@ async def show_term(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: UserToken = Depends(get_user),
|
||||
) -> List[schemas.Customer]:
|
||||
return [
|
||||
customer_info_for_list(item)
|
||||
for item in db.query(Customer).filter(Customer.phone.ilike(f"%{q}%")).order_by(Customer.name).all()
|
||||
]
|
||||
query = db.query(Customer)
|
||||
if q is not None:
|
||||
for item in q.split():
|
||||
query = query.filter(or_(Customer.name.ilike(f"%{item}%"), Customer.phone.ilike(f"%{item}%")))
|
||||
|
||||
query = query.order_by(Customer.name).all()
|
||||
return [customer_info_for_list(item) for item in query]
|
||||
|
||||
|
||||
@router.get("/{id_}", response_model=schemas.Customer)
|
||||
|
Loading…
Reference in New Issue
Block a user