修改页面分页情况

This commit is contained in:
2026-06-15 17:50:47 +08:00
parent 3aa6c7cf2f
commit d71b50c200
12 changed files with 187 additions and 64 deletions
+10 -6
View File
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, Query
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
@@ -17,14 +17,18 @@ router = APIRouter(prefix="/credits", tags=["credits"])
@router.get("", response_model=CreditBalanceOut)
async def get_credits(
page: int = Query(1, ge=1),
page_size: int = Query(20, ge=1, le=100),
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
records = await get_records(db, current_user.id)
return CreditBalanceOut(
credits=round(current_user.credits, 2),
records=[CreditRecordOut.model_validate(r) for r in records],
)
records, total = await get_records(db, current_user.id, page, page_size)
from fastapi.responses import JSONResponse
return JSONResponse(content={
"credits": round(current_user.credits, 2),
"records": [CreditRecordOut.model_validate(r) for r in records],
"total": total,
})
@router.get(