Corin1998 commited on
Commit
b256e0a
·
verified ·
1 Parent(s): 975ceb1

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +3 -5
main.py CHANGED
@@ -295,16 +295,15 @@ def list_customers(
295
  offset: int = Query(0, ge=0),
296
  session: Session = Depends(get_session),
297
  ):
298
- # 件数とデータ取得を素直に分ける(環境依存の例外を回避)
299
  base = select(Customer)
300
  count_stmt = select(func.count(Customer.id))
301
 
302
  if q:
303
  like = f"%{q}%"
304
  cond = (
305
- (Customer.name.ilike(like)) |
306
- (Customer.email.ilike(like)) |
307
- (Customer.phone.ilike(like))
308
  )
309
  base = base.where(cond)
310
  count_stmt = count_stmt.where(cond)
@@ -312,7 +311,6 @@ def list_customers(
312
  total = session.exec(count_stmt).scalar() or 0
313
  rows = session.exec(base.offset(offset).limit(limit)).all()
314
  return {"data": rows, "pagination": {"total": total, "limit": limit, "offset": offset}}
315
-
316
  # -------- Products --------
317
  @app.post("/products", dependencies=[Depends(require_api_key)])
318
  def create_product(payload: Product, session: Session = Depends(get_session)):
 
295
  offset: int = Query(0, ge=0),
296
  session: Session = Depends(get_session),
297
  ):
 
298
  base = select(Customer)
299
  count_stmt = select(func.count(Customer.id))
300
 
301
  if q:
302
  like = f"%{q}%"
303
  cond = (
304
+ func.lower(Customer.name).like(func.lower(like)) |
305
+ func.lower(Customer.email).like(func.lower(like)) |
306
+ func.lower(Customer.phone).like(func.lower(like))
307
  )
308
  base = base.where(cond)
309
  count_stmt = count_stmt.where(cond)
 
311
  total = session.exec(count_stmt).scalar() or 0
312
  rows = session.exec(base.offset(offset).limit(limit)).all()
313
  return {"data": rows, "pagination": {"total": total, "limit": limit, "offset": offset}}
 
314
  # -------- Products --------
315
  @app.post("/products", dependencies=[Depends(require_api_key)])
316
  def create_product(payload: Product, session: Session = Depends(get_session)):