feat:增加分页功能
This commit is contained in:
+22
-3
@@ -15,6 +15,7 @@ from model.sys_user import SysUser
|
||||
from repositories.biz_work_order import BizWorkOrderRepo
|
||||
from schemas.work_order import WorkOrderResp
|
||||
from utils.exceptions import NotFoundError, ParamError
|
||||
from utils.pagination import normalize_pagination, pagination_result
|
||||
|
||||
|
||||
def _audit(db: AsyncSession, user: SysUser, module: str, action: str, target, detail: str) -> None:
|
||||
@@ -49,9 +50,27 @@ def _resp(wo: BizWorkOrder) -> WorkOrderResp:
|
||||
)
|
||||
|
||||
|
||||
async def list_work_orders(db: AsyncSession, status: str | None = None) -> list[WorkOrderResp]:
|
||||
orders = await BizWorkOrderRepo(db).list_with_filter(status=status)
|
||||
return [_resp(o) for o in orders]
|
||||
async def list_work_orders(
|
||||
db: AsyncSession,
|
||||
status: str | None = None,
|
||||
*,
|
||||
page: int = 1,
|
||||
page_size: int = 10,
|
||||
) -> dict:
|
||||
"""分页查询公共工单,默认每页 10 条。"""
|
||||
page, page_size, offset = normalize_pagination(page, page_size)
|
||||
repo = BizWorkOrderRepo(db)
|
||||
orders = await repo.list_with_filter(
|
||||
status=status,
|
||||
limit=page_size,
|
||||
offset=offset,
|
||||
)
|
||||
return pagination_result(
|
||||
[_resp(o).model_dump(mode="json") for o in orders],
|
||||
await repo.count_with_filter(status=status),
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
)
|
||||
|
||||
|
||||
async def get_work_order(db: AsyncSession, work_order_id: int) -> WorkOrderResp:
|
||||
|
||||
Reference in New Issue
Block a user