Skip to content

Commit

Permalink
fix pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo committed Nov 1, 2024
1 parent 1b3128f commit d672a77
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from math import ceil
from typing import Any, Protocol, TypedDict, Union, runtime_checkable
from typing import Any, Protocol, runtime_checkable
from typing_extensions import TypedDict

from common_library.pydantic_networks_extension import AnyHttpUrlLegacy
from pydantic import TypeAdapter
Expand Down Expand Up @@ -29,7 +30,7 @@ def replace_query_params(self, **kwargs: Any) -> "_StarletteURL":
...


_URLType = Union[_YarlURL, _StarletteURL]
_URLType = _YarlURL | _StarletteURL


def _replace_query(url: _URLType, query: dict[str, Any]) -> str:
Expand Down Expand Up @@ -69,9 +70,11 @@ def paginate_data(
"""
last_page = ceil(total / limit) - 1

data = [item.model_dump() if hasattr(item, "model_dump") else item for item in chunk]

return PageDict(
_meta=PageMetaInfoLimitOffset(
total=total, count=len(chunk), limit=limit, offset=offset
total=total, count=len(data), limit=limit, offset=offset
),
_links=PageLinks(
self=_replace_query(request_url, {"offset": offset, "limit": limit}),
Expand All @@ -91,5 +94,5 @@ def paginate_data(
request_url, {"offset": last_page * limit, "limit": limit}
),
),
data=chunk,
data=data,
)

0 comments on commit d672a77

Please sign in to comment.