mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-30 07:46:13 +00:00
- 修改接口定义,增加路径参数并完善请求描述,增强参数校验和依赖注入 - 优化CRUD层数据库操作,统一异步会话使用,删除多余db参数 - 增加业务表与字段模型关系级联删除配置,优化模型关联关系声明 - 精简pydantic模型,去除冗余校验装饰器,完善字段描述和必填约束 - 服务层增加类型检查和异常抛出,规范业务逻辑流程和错误提示 - 优化代码结构,调整模块导入顺序和注释,提升代码可读性和一致性
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Dict, List, Optional, Sequence
|
|
|
|
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, None]):
|
|
"""操作日志数据层"""
|
|
|
|
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]:
|
|
"""
|
|
创建操作日志记录
|
|
|
|
:param data: 操作日志创建模型
|
|
:return: 操作日志记录
|
|
"""
|
|
return await self.create(data=data.model_dump())
|
|
|
|
async def get_by_id_crud(self, id: int) -> Optional[OperationLogModel]:
|
|
"""
|
|
根据ID获取操作日志详情
|
|
|
|
:param id: 操作日志ID
|
|
:return: 操作日志记录
|
|
"""
|
|
return await self.get(id=id)
|
|
|
|
async def get_list_crud(self, search: Optional[Dict] = None, order_by: Optional[List[Dict[str, str]]] = None) -> Sequence[OperationLogModel]:
|
|
"""
|
|
获取操作日志列表
|
|
|
|
:param search: 搜索条件
|
|
:param order_by: 排序字段
|
|
:return: 操作日志列表
|
|
"""
|
|
return await self.list(search=search, order_by=order_by)
|
|
|