This commit is contained in:
fengchuanhn@gmail.com
2026-05-17 12:54:13 +08:00
parent 1b8ca10ec9
commit 3db327d93b
38 changed files with 2820 additions and 14 deletions

View File

@@ -13,3 +13,31 @@ class ApiResponse(BaseModel, Generic[T]):
ok: bool
message: str = ""
data: T | None = None
class PaginatedData(BaseModel, Generic[T]):
"""分页列表载荷。"""
items: list[T]
total: int
page: int
page_size: int
total_pages: int
@classmethod
def build(
cls,
items: list[T],
*,
total: int,
page: int,
page_size: int,
) -> "PaginatedData[T]":
total_pages = (total + page_size - 1) // page_size if total > 0 else 0
return cls(
items=items,
total=total,
page=page,
page_size=page_size,
total_pages=total_pages,
)