mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 05:02:57 +00:00
refactor: 大规模代码重构与项目配置优化
- 调整前端路由前缀为 /web 并新增配置项 - 重构环境变量配置,替换旧环境文件为 dev/prod/test 版本 - 优化后端接口路由与参数校验,替换 dataclass 查询参数为 Pydantic 模型 - 整理后端导入顺序,延迟加载循环依赖模块 - 统一前端 API 调用命名,重构模块命名 - 新增多种响应类型支持,优化代码模板 - 简化后端路由装饰器写法,合并配置参数
This commit is contained in:
@@ -6,18 +6,11 @@ from fastapi_cache import FastAPICache
|
||||
from fastapi_cache.decorator import cache
|
||||
|
||||
from app.common.response import ResponseSchema, SuccessResponse
|
||||
from app.core.base_params import PaginationQueryParam
|
||||
from app.core.base_schema import AuthSchema, PageResultSchema
|
||||
from app.core.base_schema import AuthSchema, PageResultSchema, PaginationQueryParam
|
||||
from app.core.dependencies import AuthPermission
|
||||
from app.core.router_class import OperationLogRoute
|
||||
|
||||
from .schema import (
|
||||
PluginCreateSchema,
|
||||
PluginInstallSchema,
|
||||
PluginOutSchema,
|
||||
PluginQueryParam,
|
||||
PluginUpdateSchema,
|
||||
)
|
||||
from .schema import PluginCreateSchema, PluginInstallSchema, PluginOutSchema, PluginQueryParam, PluginUpdateSchema
|
||||
from .service import PluginService
|
||||
|
||||
PluginRouter = APIRouter(route_class=OperationLogRoute, prefix="/plugin", tags=["插件管理"])
|
||||
@@ -25,11 +18,7 @@ PluginRouter = APIRouter(route_class=OperationLogRoute, prefix="/plugin", tags=[
|
||||
_PLUGIN_NS = "plugin"
|
||||
|
||||
|
||||
@PluginRouter.get(
|
||||
"/list",
|
||||
summary="插件列表",
|
||||
response_model=ResponseSchema[PageResultSchema[PluginOutSchema]],
|
||||
)
|
||||
@PluginRouter.get("/list", summary="插件列表", response_model=ResponseSchema[PageResultSchema[PluginOutSchema]])
|
||||
@cache(expire=300, namespace=_PLUGIN_NS)
|
||||
async def plugin_list_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:query"]))],
|
||||
@@ -45,11 +34,7 @@ async def plugin_list_controller(
|
||||
return SuccessResponse(data=r, msg="查询成功")
|
||||
|
||||
|
||||
@PluginRouter.get(
|
||||
"/detail/{id}",
|
||||
summary="插件详情",
|
||||
response_model=ResponseSchema[PluginOutSchema],
|
||||
)
|
||||
@PluginRouter.get("/detail/{id}", summary="插件详情", response_model=ResponseSchema[PluginOutSchema])
|
||||
async def plugin_detail_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:query"]))],
|
||||
id: Annotated[int, Path(description="插件ID", ge=1)],
|
||||
@@ -57,11 +42,7 @@ async def plugin_detail_controller(
|
||||
return SuccessResponse(data=await PluginService(auth).detail(id=id), msg="查询成功")
|
||||
|
||||
|
||||
@PluginRouter.post(
|
||||
"/create",
|
||||
summary="创建插件",
|
||||
response_model=ResponseSchema[PluginOutSchema],
|
||||
)
|
||||
@PluginRouter.post("/create", summary="创建插件", response_model=ResponseSchema[PluginOutSchema])
|
||||
async def plugin_create_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:create"]))],
|
||||
data: Annotated[PluginCreateSchema, Body(description="插件创建参数")],
|
||||
@@ -71,11 +52,7 @@ async def plugin_create_controller(
|
||||
return SuccessResponse(data=r, msg="创建成功")
|
||||
|
||||
|
||||
@PluginRouter.put(
|
||||
"/update/{id}",
|
||||
summary="更新插件",
|
||||
response_model=ResponseSchema[PluginOutSchema],
|
||||
)
|
||||
@PluginRouter.put("/update/{id}", summary="更新插件", response_model=ResponseSchema[PluginOutSchema])
|
||||
async def plugin_update_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:update"]))],
|
||||
id: Annotated[int, Path(description="插件ID", ge=1)],
|
||||
@@ -86,11 +63,7 @@ async def plugin_update_controller(
|
||||
return SuccessResponse(data=r, msg="更新成功")
|
||||
|
||||
|
||||
@PluginRouter.delete(
|
||||
"/delete",
|
||||
summary="删除插件",
|
||||
response_model=ResponseSchema[None],
|
||||
)
|
||||
@PluginRouter.delete("/delete", summary="删除插件", response_model=ResponseSchema[None])
|
||||
async def plugin_delete_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:delete"]))],
|
||||
ids: Annotated[list[int], Body(description="插件ID列表")],
|
||||
@@ -100,11 +73,7 @@ async def plugin_delete_controller(
|
||||
return SuccessResponse(msg="删除成功")
|
||||
|
||||
|
||||
@PluginRouter.get(
|
||||
"/marketplace",
|
||||
summary="插件市场",
|
||||
response_model=ResponseSchema[PageResultSchema[PluginOutSchema]],
|
||||
)
|
||||
@PluginRouter.get("/marketplace", summary="插件市场", response_model=ResponseSchema[PageResultSchema[PluginOutSchema]])
|
||||
@cache(expire=600, namespace=_PLUGIN_NS)
|
||||
async def plugin_marketplace_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:query"]))],
|
||||
@@ -115,11 +84,7 @@ async def plugin_marketplace_controller(
|
||||
return SuccessResponse(data=r, msg="查询成功")
|
||||
|
||||
|
||||
@PluginRouter.post(
|
||||
"/install",
|
||||
summary="安装插件",
|
||||
response_model=ResponseSchema[None],
|
||||
)
|
||||
@PluginRouter.post("/install", summary="安装插件", response_model=ResponseSchema[None])
|
||||
async def plugin_install_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:install"]))],
|
||||
data: Annotated[PluginInstallSchema, Body(description="插件安装参数")],
|
||||
@@ -129,11 +94,7 @@ async def plugin_install_controller(
|
||||
return SuccessResponse(msg="安装成功")
|
||||
|
||||
|
||||
@PluginRouter.post(
|
||||
"/uninstall",
|
||||
summary="卸载插件",
|
||||
response_model=ResponseSchema[None],
|
||||
)
|
||||
@PluginRouter.post("/uninstall", summary="卸载插件", response_model=ResponseSchema[None])
|
||||
async def plugin_uninstall_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:uninstall"]))],
|
||||
data: Annotated[PluginInstallSchema, Body(description="插件卸载参数")],
|
||||
@@ -143,11 +104,7 @@ async def plugin_uninstall_controller(
|
||||
return SuccessResponse(msg="卸载成功")
|
||||
|
||||
|
||||
@PluginRouter.post(
|
||||
"/toggle",
|
||||
summary="启用/禁用插件",
|
||||
response_model=ResponseSchema[None],
|
||||
)
|
||||
@PluginRouter.post("/toggle", summary="启用/禁用插件", response_model=ResponseSchema[None])
|
||||
async def plugin_toggle_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:toggle"]))],
|
||||
data: Annotated[PluginInstallSchema, Body(description="插件启用/禁用参数")],
|
||||
@@ -157,11 +114,7 @@ async def plugin_toggle_controller(
|
||||
return SuccessResponse(msg="操作成功")
|
||||
|
||||
|
||||
@PluginRouter.get(
|
||||
"/my",
|
||||
summary="我的插件",
|
||||
response_model=ResponseSchema[list[PluginOutSchema]],
|
||||
)
|
||||
@PluginRouter.get("/my", summary="我的插件", response_model=ResponseSchema[list[PluginOutSchema]])
|
||||
@cache(expire=120, namespace=_PLUGIN_NS)
|
||||
async def plugin_my_list_controller(
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_platform:plugin:query"]))],
|
||||
@@ -169,12 +122,7 @@ async def plugin_my_list_controller(
|
||||
return SuccessResponse(data=await PluginService(auth).my_plugins(), msg="查询成功")
|
||||
|
||||
|
||||
@PluginRouter.post(
|
||||
"/reload",
|
||||
summary="热重载插件路由",
|
||||
response_model=ResponseSchema[str],
|
||||
dependencies=[Depends(AuthPermission(["module_platform:plugin:reload"]))],
|
||||
)
|
||||
@PluginRouter.post("/reload", summary="热重载插件路由", response_model=ResponseSchema[str], dependencies=[Depends(AuthPermission(["module_platform:plugin:reload"]))])
|
||||
async def plugin_reload_controller() -> JSONResponse:
|
||||
msg = PluginService.reload()
|
||||
await FastAPICache.clear(namespace=_PLUGIN_NS)
|
||||
|
||||
Reference in New Issue
Block a user