Feature: Guestbook phone autosearch also searches names.

This commit is contained in:
Amritanshu Agrawal 2021-04-02 18:52:22 +05:30
parent 78dcd6b92a
commit 91451eebc9

View File

@ -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)