mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 04:46:26 +00:00
- 移除原监控仪表盘独立模块,将相关功能合并到在线监控模块 - 重构租户配置字段名,统一使用logo_url和name替代tenant_logo/tenant_name - 优化搜索工具函数,移除重复导入 - 调整参数配置模型字段长度限制,移除config_value的max_length约束 - 清理冗余的常量定义和导入语句 - 修复批量状态设置接口的redis依赖注入 - 增强OAuth登录安全性,添加租户默认归属和state一次性消费 - 优化资源目录缓存逻辑,减少重复计算 - 新增API Token模块基础框架 - 完善用户token版本管理,支持主动失效JWT - 调整AI模型配置缓存过期时间 - 修复菜单类型字段索引,提升查询性能 - 简化前端刷新token调用逻辑 - 新增滑块验证完成接口和忘记密码验证码校验 - 调整系统配置默认值,添加操作日志保留天数和接口白名单配置 - 限制Mock支付回调仅在开发环境可用 - 重构websocket认证方式,支持更安全的subprotocol传参
77 lines
2.9 KiB
Python
77 lines
2.9 KiB
Python
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.core.base_schema import AuthSchema, PageResultSchema
|
|
from app.core.exceptions import CustomException
|
|
from app.utils.common_util import search_to_dict
|
|
|
|
from .crud import VersionCRUD
|
|
from .schema import (
|
|
VersionCreateSchema,
|
|
VersionOutSchema,
|
|
VersionQueryParam,
|
|
VersionStatusSchema,
|
|
VersionUpdateSchema,
|
|
)
|
|
|
|
|
|
class VersionService:
|
|
"""版本管理模块服务层"""
|
|
|
|
def __init__(self, auth: AuthSchema, db: AsyncSession) -> None:
|
|
self.auth = auth
|
|
self.db = db
|
|
|
|
async def detail(self, id: int) -> VersionOutSchema:
|
|
obj = await VersionCRUD(self.auth, self.db).get(id=id)
|
|
if not obj:
|
|
raise CustomException(msg="该数据不存在")
|
|
return VersionOutSchema.model_validate(obj)
|
|
|
|
async def page(
|
|
self,
|
|
page_no: int,
|
|
page_size: int,
|
|
search: VersionQueryParam | None = None,
|
|
order_by: list[dict[str, str]] | None = None,
|
|
) -> PageResultSchema[VersionOutSchema]:
|
|
offset = (page_no - 1) * page_size
|
|
return await VersionCRUD(self.auth, self.db).page(
|
|
offset=offset,
|
|
limit=page_size,
|
|
order_by=order_by or [{"sort": "asc"}, {"id": "desc"}],
|
|
search=search_to_dict(search, {}),
|
|
out_schema=VersionOutSchema,
|
|
)
|
|
|
|
async def create(self, data: VersionCreateSchema) -> VersionOutSchema:
|
|
obj = await VersionCRUD(self.auth, self.db).create(data=data)
|
|
return VersionOutSchema.model_validate(obj)
|
|
|
|
async def update(self, id: int, data: VersionUpdateSchema) -> VersionOutSchema:
|
|
obj = await VersionCRUD(self.auth, self.db).get(id=id)
|
|
if not obj:
|
|
raise CustomException(msg="更新失败,该数据不存在")
|
|
obj = await VersionCRUD(self.auth, self.db).update(id=id, data=data)
|
|
return VersionOutSchema.model_validate(obj)
|
|
|
|
async def delete(self, ids: list[int]) -> None:
|
|
if not ids:
|
|
raise CustomException(msg="删除失败,删除对象不能为空")
|
|
objs = await VersionCRUD(self.auth, self.db).get_list(search={"id": ("in", ids)})
|
|
obj_map = {o.id: o for o in objs}
|
|
for id_ in ids:
|
|
if id_ not in obj_map:
|
|
raise CustomException(msg="删除失败,该数据不存在")
|
|
await VersionCRUD(self.auth, self.db).delete(ids=ids)
|
|
|
|
async def set_status(self, id: int, data: VersionStatusSchema) -> VersionOutSchema:
|
|
obj = await VersionCRUD(self.auth, self.db).set_status(id=id, status=data.status)
|
|
return VersionOutSchema.model_validate(obj)
|
|
|
|
async def get_published(self) -> list[VersionOutSchema]:
|
|
objs = await VersionCRUD(self.auth, self.db).get_list(
|
|
search={"status": ("eq", 1)},
|
|
order_by=[{"sort": "asc"}],
|
|
)
|
|
return [VersionOutSchema.model_validate(obj) for obj in objs]
|