mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 13:05:18 +00:00
这是一次综合性的重构更新,包含以下主要变更: 1. 升级Python版本到3.12,更新依赖配置 2. 替换旧的.j2模板为.jinja2格式,新增代码生成模板 3. 重构权限过滤策略,更新权限枚举与模型配置 4. 移除Prefect依赖,替换为自研拓扑并行执行引擎 5. 重构认证与上下文管理,拆分租户/请求上下文 6. 简化响应模型、CRUD与服务层代码 7. 清理废弃的支付网关模块,重构订单定时任务 8. 更新在线用户、监控等模块的接口与路由 9. 优化邮件模板与工具类,新增邮件模板文件 10. 修复数据库会话配置与类型提示
104 lines
3.5 KiB
Python
104 lines
3.5 KiB
Python
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Body, Depends, Path
|
|
from fastapi.responses import JSONResponse
|
|
from fastapi_cache import FastAPICache
|
|
from fastapi_cache.decorator import cache
|
|
|
|
from app.common.response import ResponseSchema, SuccessResponse
|
|
from app.core.base_schema import AuthSchema, BatchSetAvailable
|
|
from app.core.dependencies import AuthPermission
|
|
from app.core.router_class import OperationLogRoute
|
|
|
|
from .schema import MenuCreateSchema, MenuOutSchema, MenuQueryParam, MenuUpdateSchema
|
|
from .service import MenuService
|
|
|
|
MenuRouter = APIRouter(route_class=OperationLogRoute, prefix="/menu", tags=["平台管理", "菜单管理"])
|
|
|
|
_MENU_NS = "menu"
|
|
|
|
|
|
@MenuRouter.get(
|
|
"/tree",
|
|
summary="查询菜单树",
|
|
response_model=ResponseSchema[list[MenuOutSchema]],
|
|
)
|
|
@cache(expire=300, namespace=_MENU_NS)
|
|
async def get_menu_tree_controller(
|
|
search: Annotated[MenuQueryParam, Depends()],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:menu:query"]))],
|
|
) -> JSONResponse:
|
|
order_by = [{"order": "asc"}]
|
|
result_dict_tree = await MenuService(auth).tree(search=search, order_by=order_by)
|
|
return SuccessResponse(data=result_dict_tree, msg="查询菜单树成功")
|
|
|
|
|
|
@MenuRouter.get(
|
|
"/detail/{id}",
|
|
summary="查询菜单详情",
|
|
response_model=ResponseSchema[MenuOutSchema],
|
|
)
|
|
async def get_obj_detail_controller(
|
|
id: Annotated[int, Path(description="菜单ID")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:menu:detail"]))],
|
|
) -> JSONResponse:
|
|
result_dict = await MenuService(auth).detail(id=id)
|
|
return SuccessResponse(data=result_dict, msg="查询菜单详情成功")
|
|
|
|
|
|
@MenuRouter.post(
|
|
"/create",
|
|
summary="创建菜单",
|
|
response_model=ResponseSchema[MenuOutSchema],
|
|
)
|
|
async def create_obj_controller(
|
|
data: MenuCreateSchema,
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:menu:create"]))],
|
|
) -> JSONResponse:
|
|
result_dict = await MenuService(auth).create(data=data)
|
|
await FastAPICache.clear(namespace=_MENU_NS)
|
|
return SuccessResponse(data=result_dict, msg="创建菜单成功")
|
|
|
|
|
|
@MenuRouter.put(
|
|
"/update/{id}",
|
|
summary="修改菜单",
|
|
response_model=ResponseSchema[MenuOutSchema],
|
|
)
|
|
async def update_obj_controller(
|
|
data: MenuUpdateSchema,
|
|
id: Annotated[int, Path(description="菜单ID")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:menu:update"]))],
|
|
) -> JSONResponse:
|
|
result_dict = await MenuService(auth).update(id=id, data=data)
|
|
await FastAPICache.clear(namespace=_MENU_NS)
|
|
return SuccessResponse(data=result_dict, msg="修改菜单成功")
|
|
|
|
|
|
@MenuRouter.delete(
|
|
"/delete",
|
|
summary="删除菜单",
|
|
response_model=ResponseSchema[None],
|
|
)
|
|
async def delete_obj_controller(
|
|
ids: Annotated[list[int], Body(description="ID列表")],
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:menu:delete"]))],
|
|
) -> JSONResponse:
|
|
await MenuService(auth).delete(ids=ids)
|
|
await FastAPICache.clear(namespace=_MENU_NS)
|
|
return SuccessResponse(msg="删除菜单成功")
|
|
|
|
|
|
@MenuRouter.patch(
|
|
"/status/batch",
|
|
summary="批量修改菜单状态",
|
|
response_model=ResponseSchema[None],
|
|
)
|
|
async def batch_set_available_obj_controller(
|
|
data: BatchSetAvailable,
|
|
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:menu:patch"]))],
|
|
) -> JSONResponse:
|
|
await MenuService(auth).set_available(data=data)
|
|
await FastAPICache.clear(namespace=_MENU_NS)
|
|
return SuccessResponse(msg="批量修改菜单状态成功")
|