mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2025-08-26 13:26:04 +08:00
Add business pagination in the code generator (#757)
This commit is contained in:
@ -2,12 +2,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Depends, Path
|
||||
from fastapi import APIRouter, Depends, Path, Query
|
||||
|
||||
from backend.common.pagination import DependsPagination, PageData, paging_data
|
||||
from backend.common.response.response_schema import ResponseModel, ResponseSchemaModel, response_base
|
||||
from backend.common.security.jwt import DependsJwtAuth
|
||||
from backend.common.security.permission import RequestPermission
|
||||
from backend.common.security.rbac import DependsRBAC
|
||||
from backend.database.db import CurrentSession
|
||||
from backend.plugin.code_generator.schema.business import (
|
||||
CreateGenBusinessParam,
|
||||
GetGenBusinessDetail,
|
||||
@ -28,10 +30,21 @@ async def get_business(
|
||||
return response_base.success(data=data)
|
||||
|
||||
|
||||
@router.get('', summary='获取所有代码生成业务', dependencies=[DependsJwtAuth])
|
||||
async def get_all_businesses() -> ResponseSchemaModel[list[GetGenBusinessDetail]]:
|
||||
data = await gen_business_service.get_all()
|
||||
return response_base.success(data=data)
|
||||
@router.get(
|
||||
'',
|
||||
summary='分页获取所有代码生成业务',
|
||||
dependencies=[
|
||||
DependsJwtAuth,
|
||||
DependsPagination,
|
||||
],
|
||||
)
|
||||
async def get_businesses_paged(
|
||||
db: CurrentSession,
|
||||
table_name: Annotated[str | None, Query(description='代码生成业务表名称')] = None,
|
||||
) -> ResponseSchemaModel[PageData[GetGenBusinessDetail]]:
|
||||
business_select = await gen_business_service.get_select(table_name=table_name)
|
||||
page_data = await paging_data(db, business_select)
|
||||
return response_base.success(data=page_data)
|
||||
|
||||
|
||||
@router.get('/{pk}/models', summary='获取代码生成业务所有模型', dependencies=[DependsJwtAuth])
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
from typing import Sequence
|
||||
|
||||
from sqlalchemy import Select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy_crud_plus import CRUDPlus
|
||||
|
||||
@ -32,14 +32,19 @@ class CRUDGenBusiness(CRUDPlus[GenBusiness]):
|
||||
"""
|
||||
return await self.select_model_by_column(db, table_name=name)
|
||||
|
||||
async def get_all(self, db: AsyncSession) -> Sequence[GenBusiness]:
|
||||
async def get_list(self, table_name: str | None) -> Select:
|
||||
"""
|
||||
获取所有代码生成业务
|
||||
|
||||
:param db: 数据库会话
|
||||
:param table_name: 业务表名
|
||||
:return:
|
||||
"""
|
||||
return await self.select_models(db)
|
||||
filters = {}
|
||||
|
||||
if table_name is not None:
|
||||
filters['table_name__like'] = f'%{table_name}%'
|
||||
|
||||
return await self.select_order('id', 'desc', **filters)
|
||||
|
||||
async def create(self, db: AsyncSession, obj: CreateGenBusinessParam) -> None:
|
||||
"""
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
from typing import Sequence
|
||||
|
||||
from sqlalchemy import Select
|
||||
|
||||
from backend.common.exception import errors
|
||||
from backend.database.db import async_db_session
|
||||
@ -27,10 +28,14 @@ class GenBusinessService:
|
||||
return business
|
||||
|
||||
@staticmethod
|
||||
async def get_all() -> Sequence[GenBusiness]:
|
||||
"""获取所有业务"""
|
||||
async with async_db_session() as db:
|
||||
return await gen_business_dao.get_all(db)
|
||||
async def get_select(*, table_name: str) -> Select:
|
||||
"""
|
||||
获取代码生成业务列表查询条件
|
||||
|
||||
:param table_name: 业务表名
|
||||
:return:
|
||||
"""
|
||||
return await gen_business_dao.get_list(table_name=table_name)
|
||||
|
||||
@staticmethod
|
||||
async def create(*, obj: CreateGenBusinessParam) -> None:
|
||||
|
Reference in New Issue
Block a user