13 lines
369 B
Python
13 lines
369 B
Python
from __future__ import annotations
|
|
|
|
from typing import TypeVar
|
|
|
|
from app.schemas.common import PaginatedResponse
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
def paginate(items: list[T], total: int, page: int, size: int) -> PaginatedResponse[T]:
|
|
pages = (total + size - 1) // size if size > 0 else 0
|
|
return PaginatedResponse(items=items, total=total, page=page, size=size, pages=pages)
|