mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 05:02:57 +00:00
refactor: 重构数据库连接模块,提高可维护性 docs: 更新README.md项目描述 style: 调整日志输出格式和内容 refactor: 优化中间件日志记录逻辑 style: 统一代码中的空行和导入顺序 refactor: 分离数据库引擎和会话创建逻辑 style: 清理未使用的导入和代码 refactor: 重命名数据库会话变量 style: 调整jinja2模板变量命名 refactor: 优化异常处理和日志记录 style: 统一字符串格式化方式 refactor: 优化redis连接错误处理 style: 调整注释格式和位置 refactor: 优化数据库连接配置 style: 清理多余空行和注释
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Dict, List, Optional, Sequence, Union, Any
|
|
|
|
from app.core.base_crud import CRUDBase
|
|
|
|
from ..auth.schema import AuthSchema
|
|
from .model import OperationLogModel
|
|
from .schema import OperationLogCreateSchema
|
|
|
|
|
|
class OperationLogCRUD(CRUDBase[OperationLogModel, OperationLogCreateSchema, OperationLogCreateSchema]):
|
|
"""
|
|
操作日志数据层。
|
|
"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
"""
|
|
初始化操作日志CRUD。
|
|
"""
|
|
self.auth = auth
|
|
super().__init__(model=OperationLogModel, auth=auth)
|
|
|
|
async def create_crud(self, data: OperationLogCreateSchema) -> Optional[OperationLogModel]:
|
|
"""
|
|
创建操作日志记录。
|
|
|
|
参数:
|
|
- data (OperationLogCreateSchema): 操作日志创建模型。
|
|
|
|
返回:
|
|
- OperationLogModel | None: 创建后的日志记录。
|
|
"""
|
|
return await self.create(data=data)
|
|
|
|
async def get_by_id_crud(self, id: int, preload: Optional[List[Union[str, Any]]] = None) -> Optional[OperationLogModel]:
|
|
"""
|
|
根据ID获取操作日志详情。
|
|
|
|
参数:
|
|
- id (int): 操作日志ID。
|
|
- preload (Optional[List[Union[str, Any]]]): 预加载关系,未提供时使用模型默认项
|
|
|
|
返回:
|
|
- OperationLogModel | None: 操作日志记录。
|
|
"""
|
|
return await self.get(id=id, preload=preload)
|
|
|
|
async def get_list_crud(self, search: Optional[Dict] = None, order_by: Optional[List[Dict[str, str]]] = None, preload: Optional[List[Union[str, Any]]] = None) -> Sequence[OperationLogModel]:
|
|
"""
|
|
获取操作日志列表。
|
|
|
|
参数:
|
|
- search (Dict | None): 搜索条件字典。
|
|
- order_by (List[Dict[str, str]] | None): 排序字段列表。
|
|
- preload (Optional[List[Union[str, Any]]]): 预加载关系,未提供时使用模型默认项
|
|
|
|
返回:
|
|
- Sequence[OperationLogModel]: 操作日志列表。
|
|
"""
|
|
return await self.list(search=search, order_by=order_by, preload=preload) |