修改页面分页情况

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
+7 -2
View File
@@ -282,10 +282,15 @@ async def refund_credits(
)
async def get_records(db: AsyncSession, user_id: str) -> list[CreditRecord]:
async def get_records(db: AsyncSession, user_id: str, page: int = 1, page_size: int = 20) -> tuple[list[CreditRecord], int]:
count_query = select(func.count(CreditRecord.id)).where(CreditRecord.user_id == user_id)
total = (await db.execute(count_query)).scalar() or 0
result = await db.execute(
select(CreditRecord)
.where(CreditRecord.user_id == user_id)
.order_by(CreditRecord.created_at.desc())
.offset((page - 1) * page_size)
.limit(page_size)
)
return list(result.scalars().all())
return list(result.scalars().all()), total