22
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user