修改页面分页情况
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user