mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
refactor: 完成项目整体架构升级与依赖优化
此提交包含多项核心优化: 1. 依赖库升级:更新FastAPI、替换fastapi-limiter为slowapi,更换MySQL驱动为aiomysql,重构缓存系统使用fastapi-cache2-fork 2. 代码重构:移除自定义缓存工具,统一使用fastapi-cache2;重构请求限流逻辑,修复操作日志记录开关逻辑 3. 接口规范:统一将Depends分页/查询参数改为Query注解,补全File上传依赖注解 4. 前端优化:调整登录滑块进度条颜色、移除冗余demo页面样式类 5. 日志优化:重构日志配置,使用time.perf_counter替代time.time统计耗时 6. 测试优化:移除冗余的限流mock配置,改用官方限流方案 7. 模板优化:更新vue代码生成模板,移除冗余导入并优化组件使用 8. 导入功能优化:移除pandas依赖,使用Excel工具类重构文件导入逻辑
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Body, Depends, Path
|
||||
from fastapi import APIRouter, Body, Depends, Path, Query
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from app.common.response import ResponseSchema, SuccessResponse
|
||||
from app.core import cache_util
|
||||
from app.core.base_schema import AuthSchema, BatchSetAvailable
|
||||
from app.core.cache_util import cache
|
||||
from app.core.dependencies import AuthPermission
|
||||
from app.core.router_class import OperationLogRoute
|
||||
from fastapi_cache import FastAPICache
|
||||
from fastapi_cache.decorator import cache
|
||||
|
||||
from .schema import DeptCreateSchema, DeptOutSchema, DeptQueryParam, DeptUpdateSchema
|
||||
from .service import DeptService
|
||||
@@ -24,8 +24,8 @@ _DEPT_NS = "dept"
|
||||
)
|
||||
@cache(expire=300, namespace=_DEPT_NS)
|
||||
async def get_dept_tree_controller(
|
||||
search: Annotated[DeptQueryParam, Depends()],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:query"]))],
|
||||
search: Annotated[DeptQueryParam, Query(description="部门查询参数")],
|
||||
) -> JSONResponse:
|
||||
order_by = [{"order": "asc"}]
|
||||
result_dict_tree = await DeptService(auth).tree(search=search, order_by=order_by)
|
||||
@@ -37,8 +37,8 @@ async def get_dept_tree_controller(
|
||||
response_model=ResponseSchema[DeptOutSchema],
|
||||
)
|
||||
async def get_obj_detail_controller(
|
||||
id: Annotated[int, Path(description="部门ID")],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:detail"]))],
|
||||
id: Annotated[int, Path(description="部门ID")],
|
||||
) -> JSONResponse:
|
||||
result_dict = await DeptService(auth).detail(id=id)
|
||||
return SuccessResponse(data=result_dict, msg="查询部门详情成功")
|
||||
@@ -49,11 +49,11 @@ async def get_obj_detail_controller(
|
||||
response_model=ResponseSchema[DeptOutSchema],
|
||||
)
|
||||
async def create_obj_controller(
|
||||
data: DeptCreateSchema,
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:create"]))],
|
||||
data: Annotated[DeptCreateSchema, Body(description="部门创建参数")],
|
||||
) -> JSONResponse:
|
||||
result_dict = await DeptService(auth).create(data=data)
|
||||
await cache_util.clear(namespace=_DEPT_NS)
|
||||
await FastAPICache.clear(namespace=_DEPT_NS)
|
||||
return SuccessResponse(data=result_dict, msg="创建部门成功")
|
||||
|
||||
@DeptRouter.put(
|
||||
@@ -62,12 +62,12 @@ async def create_obj_controller(
|
||||
response_model=ResponseSchema[DeptOutSchema],
|
||||
)
|
||||
async def update_obj_controller(
|
||||
data: DeptUpdateSchema,
|
||||
id: Annotated[int, Path(description="部门ID")],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:update"]))],
|
||||
id: Annotated[int, Path(description="部门ID")],
|
||||
data: Annotated[DeptUpdateSchema, Body(description="部门修改参数")],
|
||||
) -> JSONResponse:
|
||||
result_dict = await DeptService(auth).update(id=id, data=data)
|
||||
await cache_util.clear(namespace=_DEPT_NS)
|
||||
await FastAPICache.clear(namespace=_DEPT_NS)
|
||||
return SuccessResponse(data=result_dict, msg="修改部门成功")
|
||||
|
||||
@DeptRouter.delete(
|
||||
@@ -76,11 +76,11 @@ async def update_obj_controller(
|
||||
response_model=ResponseSchema[None],
|
||||
)
|
||||
async def delete_obj_controller(
|
||||
ids: Annotated[list[int], Body(description="ID列表")],
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:delete"]))],
|
||||
ids: Annotated[list[int], Body(description="ID列表")],
|
||||
) -> JSONResponse:
|
||||
await DeptService(auth).delete(ids=ids)
|
||||
await cache_util.clear(namespace=_DEPT_NS)
|
||||
await FastAPICache.clear(namespace=_DEPT_NS)
|
||||
return SuccessResponse(msg="删除部门成功")
|
||||
|
||||
@DeptRouter.patch(
|
||||
@@ -89,9 +89,9 @@ async def delete_obj_controller(
|
||||
response_model=ResponseSchema[None],
|
||||
)
|
||||
async def batch_set_available_obj_controller(
|
||||
data: BatchSetAvailable,
|
||||
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:dept:patch"]))],
|
||||
data: Annotated[BatchSetAvailable, Body(description="批量修改部门状态参数")],
|
||||
) -> JSONResponse:
|
||||
await DeptService(auth).batch_set_available(data=data)
|
||||
await cache_util.clear(namespace=_DEPT_NS)
|
||||
await FastAPICache.clear(namespace=_DEPT_NS)
|
||||
return SuccessResponse(msg="批量修改部门状态成功")
|
||||
|
||||
Reference in New Issue
Block a user