From adb0df3b1796a8b0deada12b6023d3ca7ec3035f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=20=E6=9F=8F?= Date: Wed, 4 Dec 2024 15:03:41 +0900 Subject: [PATCH] AbstractPage -> update the create for new version --- backend/app/core/common.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/app/core/common.py b/backend/app/core/common.py index 5442f7a..953caaa 100644 --- a/backend/app/core/common.py +++ b/backend/app/core/common.py @@ -3,7 +3,7 @@ import math from fastapi import Query from fastapi_pagination.bases import AbstractPage,AbstractParams,RawParams from pydantic import BaseModel -from typing import Generic, List,TypeVar,Generic,Sequence +from typing import Any, Generic, List, Type,TypeVar,Generic,Sequence from fastapi_pagination import Page,utils T = TypeVar('T') @@ -42,7 +42,8 @@ class ApiReturnPage(AbstractPage[T],Generic[T]): __params_type__ =Params @classmethod - def create(cls,items:Sequence[T],total:int,params:Params) -> Page[T]: + def create(cls,items:Sequence[T],params:Params,**kwargs: Any) -> Type[Page[T]]: + total = kwargs.get('total', 0) total_pages = math.ceil(total/params.size) return utils.create_pydantic_model(cls,data=items,total=total,page=params.page,size=params.size,total_pages=total_pages)