Corin1998 commited on
Commit
f4b2b34
·
verified ·
1 Parent(s): 92634b0

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +3 -4
main.py CHANGED
@@ -302,12 +302,10 @@ def list_customers(
302
  (Customer.email.ilike(like)) |
303
  (Customer.phone.ilike(like))
304
  )
305
- # ここがポイント: .count() は使わず count クエリを投げる
306
- total = session.exec(select(func.count()).select_from(stmt.subquery())).scalar_one()
307
- python
308
  rows = session.exec(stmt.offset(offset).limit(limit)).all()
309
  return {"data": rows, "pagination": {"total": total, "limit": limit, "offset": offset}}
310
-
311
  # -------- Products --------
312
  @app.post("/products", dependencies=[Depends(require_api_key)])
313
  def create_product(payload: Product, session: Session = Depends(get_session)):
@@ -325,6 +323,7 @@ def list_products(
325
  total = session.exec(select(func.count()).select_from(base.subquery())).scalar_one()
326
  rows = session.exec(base.offset(offset).limit(limit)).all()
327
  return {"data": rows, "pagination": {"total": total, "limit": limit, "offset": offset}}
 
328
  # -------- Quotes --------
329
  @app.post("/quotes", dependencies=[Depends(require_api_key)])
330
  def create_quote(payload: CreateQuoteIn, session: Session = Depends(get_session)):
 
302
  (Customer.email.ilike(like)) |
303
  (Customer.phone.ilike(like))
304
  )
305
+ # 修正済み:余計なインデントを削除
306
+ total = session.exec(select(func.count()).select_from(stmt.subquery())).scalar_one()
 
307
  rows = session.exec(stmt.offset(offset).limit(limit)).all()
308
  return {"data": rows, "pagination": {"total": total, "limit": limit, "offset": offset}}
 
309
  # -------- Products --------
310
  @app.post("/products", dependencies=[Depends(require_api_key)])
311
  def create_product(payload: Product, session: Session = Depends(get_session)):
 
323
  total = session.exec(select(func.count()).select_from(base.subquery())).scalar_one()
324
  rows = session.exec(base.offset(offset).limit(limit)).all()
325
  return {"data": rows, "pagination": {"total": total, "limit": limit, "offset": offset}}
326
+
327
  # -------- Quotes --------
328
  @app.post("/quotes", dependencies=[Depends(require_api_key)])
329
  def create_quote(payload: CreateQuoteIn, session: Session = Depends(get_session)):