mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-23 21:18:09 +00:00
refactor: 重构前端组件和样式,添加AI助手功能 docs: 更新README文档,添加ruff代码检查说明 feat: 新增AI助手相关API和前端组件 chore: 更新.gitignore文件,添加ruff缓存配置 fix: 修复前端布局和设置相关的问题 perf: 优化代码结构和性能,移除冗余代码 test: 更新测试文件,移除编码声明 build: 更新依赖版本,调整requirements.txt
99 lines
2.8 KiB
Python
99 lines
2.8 KiB
Python
from collections.abc import Sequence
|
|
|
|
from app.api.v1.module_system.auth.schema import AuthSchema
|
|
from app.core.base_crud import CRUDBase
|
|
|
|
from .model import NoticeModel
|
|
from .schema import NoticeCreateSchema, NoticeUpdateSchema
|
|
|
|
|
|
class NoticeCRUD(CRUDBase[NoticeModel, NoticeCreateSchema, NoticeUpdateSchema]):
|
|
"""公告数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
"""
|
|
初始化公告数据层。
|
|
|
|
参数:
|
|
- auth (AuthSchema): 认证信息模型。
|
|
"""
|
|
self.auth = auth
|
|
super().__init__(model=NoticeModel, auth=auth)
|
|
|
|
async def get_by_id_crud(self, id: int, preload: list | None = None) -> NoticeModel | None:
|
|
"""
|
|
根据ID获取公告详情。
|
|
|
|
参数:
|
|
- id (int): 公告ID。
|
|
- preload (list | None): 预加载关系,未提供时使用模型默认项
|
|
|
|
返回:
|
|
- NoticeModel | None: 公告模型实例。
|
|
"""
|
|
return await self.get(id=id, preload=preload)
|
|
|
|
async def get_list_crud(self, search: dict | None = None, order_by: list[dict] | None = None, preload: list | None = None) -> Sequence[NoticeModel]:
|
|
"""
|
|
获取公告列表。
|
|
|
|
参数:
|
|
- search (dict | None): 查询参数。
|
|
- order_by (list[dict] | None): 排序参数。
|
|
- preload (list | None): 预加载关系,未提供时使用模型默认项
|
|
|
|
返回:
|
|
- Sequence[NoticeModel]: 公告模型实例列表。
|
|
"""
|
|
return await self.list(search=search, order_by=order_by, preload=preload)
|
|
|
|
async def create_crud(self, data: NoticeCreateSchema) -> NoticeModel | None:
|
|
"""
|
|
创建公告。
|
|
|
|
参数:
|
|
- data (NoticeCreateSchema): 公告创建模型。
|
|
|
|
返回:
|
|
- NoticeModel | None: 公告模型实例。
|
|
"""
|
|
return await self.create(data=data)
|
|
|
|
async def update_crud(self, id: int, data: NoticeUpdateSchema) -> NoticeModel | None:
|
|
"""
|
|
更新公告。
|
|
|
|
参数:
|
|
- id (int): 公告ID。
|
|
- data (NoticeUpdateSchema): 公告更新模型。
|
|
|
|
返回:
|
|
- NoticeModel | None: 公告模型实例。
|
|
"""
|
|
return await self.update(id=id, data=data)
|
|
|
|
async def delete_crud(self, ids: list[int]) -> None:
|
|
"""
|
|
删除公告。
|
|
|
|
参数:
|
|
- ids (list[int]): 公告ID列表。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
return await self.delete(ids=ids)
|
|
|
|
async def set_available_crud(self, ids: list[int], status: str) -> None:
|
|
"""
|
|
设置公告的可用状态。
|
|
|
|
参数:
|
|
- ids (list[int]): 公告ID列表。
|
|
- status (str): 可用状态。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
return await self.set(ids=ids, status=status)
|