mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-27 14:52:56 +00:00
style: 统一代码风格和格式 docs: 完善函数和方法的文档字符串 refactor(base_model): 移除冗余的表名和表参数生成方法 refactor(constant): 更新返回码注释格式 refactor(router_class): 添加路由处理器的详细文档 refactor(database): 完善数据库连接函数的文档 refactor(security): 添加认证类和方法的详细文档 refactor(validator): 更新验证器函数的文档格式 refactor(serialize): 优化序列化工具类的文档 refactor(response): 完善响应类的文档字符串 refactor(dependencies): 添加依赖函数的详细文档 refactor(initialize): 完善初始化脚本的文档 refactor(plugin): 添加生命周期和中间件注册的文档 refactor(service): 完善服务层方法的文档 refactor(controller): 添加控制器方法的详细文档 refactor(crud): 完善CRUD操作的文档字符串 refactor(schema): 简化模型类并移除冗余字段 refactor(param): 更新查询参数类的注释格式 refactor(template): 优化代码生成模板的格式 refactor(console): 添加控制台输出功能的实现 refactor(util): 完善工具函数的文档字符串
186 lines
6.0 KiB
Python
186 lines
6.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Dict, List, Optional, Sequence
|
|
|
|
from app.core.base_crud import CRUDBase
|
|
from app.api.v1.module_system.dict.model import DictDataModel, DictTypeModel
|
|
from app.api.v1.module_system.dict.schema import DictDataCreateSchema, DictDataUpdateSchema, DictTypeCreateSchema, DictTypeUpdateSchema
|
|
from app.api.v1.module_system.auth.schema import AuthSchema
|
|
|
|
|
|
class DictTypeCRUD(CRUDBase[DictTypeModel, DictTypeCreateSchema, DictTypeUpdateSchema]):
|
|
"""数据字典类型数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
"""
|
|
初始化数据字典类型CRUD
|
|
|
|
参数:
|
|
- auth (AuthSchema): 认证信息模型
|
|
"""
|
|
self.auth = auth
|
|
super().__init__(model=DictTypeModel, auth=auth)
|
|
|
|
async def get_obj_by_id_crud(self, id: int) -> Optional[DictTypeModel]:
|
|
"""
|
|
获取数据字典类型详情
|
|
|
|
参数:
|
|
- id (int): 数据字典类型ID
|
|
|
|
返回:
|
|
- Optional[DictTypeModel]: 数据字典类型模型,如果不存在则为None
|
|
"""
|
|
return await self.get(id=id)
|
|
|
|
async def get_obj_list_crud(self, search: Optional[Dict] = None, order_by: Optional[List[Dict[str, str]]] = None) -> Sequence[DictTypeModel]:
|
|
"""
|
|
获取数据字典类型列表
|
|
|
|
参数:
|
|
- search (Optional[Dict]): 查询参数,默认值为None
|
|
- order_by (Optional[List[Dict[str, str]]]): 排序参数,默认值为None
|
|
|
|
返回:
|
|
- Sequence[DictTypeModel]: 数据字典类型模型序列
|
|
"""
|
|
return await self.list(search=search, order_by=order_by)
|
|
|
|
async def create_obj_crud(self, data: DictTypeCreateSchema) -> Optional[DictTypeModel]:
|
|
"""
|
|
创建数据字典类型
|
|
|
|
参数:
|
|
- data (DictTypeCreateSchema): 数据字典类型创建模型
|
|
|
|
返回:
|
|
- Optional[DictTypeModel]: 创建的数据字典类型模型,如果创建失败则为None
|
|
"""
|
|
return await self.create(data=data)
|
|
|
|
async def update_obj_crud(self, id: int, data: DictTypeUpdateSchema) -> Optional[DictTypeModel]:
|
|
"""
|
|
更新数据字典类型
|
|
|
|
参数:
|
|
- id (int): 数据字典类型ID
|
|
- data (DictTypeUpdateSchema): 数据字典类型更新模型
|
|
|
|
返回:
|
|
- Optional[DictTypeModel]: 更新的数据字典类型模型,如果更新失败则为None
|
|
"""
|
|
return await self.update(id=id, data=data)
|
|
|
|
async def delete_obj_crud(self, ids: List[int]) -> None:
|
|
"""
|
|
删除数据字典类型
|
|
|
|
参数:
|
|
- ids (List[int]): 数据字典类型ID列表
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
return await self.delete(ids=ids)
|
|
|
|
async def set_obj_available_crud(self, ids: List[int], status: bool) -> None:
|
|
"""
|
|
设置数据字典类型的可用状态
|
|
|
|
参数:
|
|
- ids (List[int]): 数据字典类型ID列表
|
|
- status (bool): 可用状态,True表示可用,False表示不可用
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
return await self.set(ids=ids, status=status)
|
|
|
|
|
|
class DictDataCRUD(CRUDBase[DictDataModel, DictDataCreateSchema, DictDataUpdateSchema]):
|
|
"""数据字典数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
"""
|
|
初始化数据字典数据CRUD
|
|
|
|
参数:
|
|
- auth (AuthSchema): 认证信息模型
|
|
"""
|
|
self.auth = auth
|
|
super().__init__(model=DictDataModel, auth=auth)
|
|
|
|
async def get_obj_by_id_crud(self, id: int) -> Optional[DictDataModel]:
|
|
"""
|
|
获取数据字典数据详情
|
|
|
|
参数:
|
|
- id (int): 数据字典数据ID
|
|
|
|
返回:
|
|
- Optional[DictDataModel]: 数据字典数据模型,如果不存在则为None
|
|
"""
|
|
return await self.get(id=id)
|
|
|
|
async def get_obj_list_crud(self, search: Optional[Dict] = None, order_by: Optional[List[Dict[str, str]]] = None) -> Sequence[DictDataModel]:
|
|
"""
|
|
获取数据字典数据列表
|
|
|
|
参数:
|
|
- search (Optional[Dict]): 查询参数,默认值为None
|
|
- order_by (Optional[List[Dict[str, str]]]): 排序参数,默认值为None
|
|
|
|
返回:
|
|
- Sequence[DictDataModel]: 数据字典数据模型序列
|
|
"""
|
|
return await self.list(search=search, order_by=order_by)
|
|
|
|
async def create_obj_crud(self, data: DictDataCreateSchema) -> Optional[DictDataModel]:
|
|
"""
|
|
创建数据字典数据
|
|
|
|
参数:
|
|
- data (DictDataCreateSchema): 数据字典数据创建模型
|
|
|
|
返回:
|
|
- Optional[DictDataModel]: 创建的数据字典数据模型,如果创建失败则为None
|
|
"""
|
|
return await self.create(data=data)
|
|
|
|
async def update_obj_crud(self, id: int, data: DictDataUpdateSchema) -> Optional[DictDataModel]:
|
|
"""
|
|
更新数据字典数据
|
|
|
|
参数:
|
|
- id (int): 数据字典数据ID
|
|
- data (DictDataUpdateSchema): 数据字典数据更新模型
|
|
|
|
返回:
|
|
- Optional[DictDataModel]: 更新的数据字典数据模型,如果更新失败则为None
|
|
"""
|
|
return await self.update(id=id, data=data)
|
|
|
|
async def delete_obj_crud(self, ids: List[int]) -> None:
|
|
"""
|
|
删除数据字典数据
|
|
|
|
参数:
|
|
- ids (List[int]): 数据字典数据ID列表
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
return await self.delete(ids=ids)
|
|
|
|
async def set_obj_available_crud(self, ids: List[int], status: bool) -> None:
|
|
"""
|
|
设置数据字典数据的可用状态
|
|
|
|
参数:
|
|
- ids (List[int]): 数据字典数据ID列表
|
|
- status (bool): 可用状态,True表示可用,False表示不可用
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
return await self.set(ids=ids, status=status) |