Skip to content

Commit

Permalink
Fix serialization when pagination is empty (#491)
Browse files Browse the repository at this point in the history
* bug fix

* update codes
  • Loading branch information
qhp13654398483 authored Jan 18, 2025
1 parent 3fe0023 commit cf693cd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions backend/common/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ class _CustomPage(_PageDetails, AbstractPage[T], Generic[T]):
@classmethod
def create(
cls,
items: Sequence[SchemaT],
items: list,
total: int,
params: _CustomPageParams,
) -> _CustomPage[T]:
page = params.page
size = params.size
total_pages = ceil(total / params.size)
links = create_links(**{
'first': {'page': 1, 'size': f'{size}'},
'last': {'page': f'{ceil(total / params.size)}', 'size': f'{size}'} if total > 0 else 1,
'next': {'page': f'{page + 1}', 'size': f'{size}'} if (page + 1) <= total_pages else None,
'prev': {'page': f'{page - 1}', 'size': f'{size}'} if (page - 1) >= 1 else None,
}).model_dump()
links = create_links(
first={'page': 1, 'size': size},
last={'page': f'{ceil(total / params.size)}', 'size': size} if total > 0 else {'page': 1, 'size': size},
next={'page': f'{page + 1}', 'size': size} if (page + 1) <= total_pages else None,
prev={'page': f'{page - 1}', 'size': size} if (page - 1) >= 1 else None,
).model_dump()

return cls(
items=items,
total=total,
page=params.page,
size=params.size,
total_pages=total_pages,
links=links,
links=links, # type: ignore
)


Expand Down

0 comments on commit cf693cd

Please sign in to comment.