mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 20:55:14 +00:00
refactor: 优化代码注释和文档字符串格式
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): 完善工具函数的文档字符串
This commit is contained in:
@@ -21,19 +21,47 @@ class RoleService:
|
||||
|
||||
@classmethod
|
||||
async def get_role_detail_service(cls, auth: AuthSchema, id: int) -> Dict:
|
||||
"""获取角色详情"""
|
||||
"""
|
||||
获取角色详情
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型
|
||||
- id (int): 角色ID
|
||||
|
||||
返回:
|
||||
- Dict: 角色详情字典
|
||||
"""
|
||||
role = await RoleCRUD(auth).get_by_id_crud(id=id)
|
||||
return RoleOutSchema.model_validate(role).model_dump()
|
||||
|
||||
@classmethod
|
||||
async def get_role_list_service(cls, auth: AuthSchema, search: Optional[RoleQueryParam] = None, order_by: Optional[List[Dict[str, str]]] = None) -> List[Dict]:
|
||||
"""获取角色列表"""
|
||||
"""
|
||||
获取角色列表
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型
|
||||
- search (Optional[RoleQueryParam]): 查询参数模型
|
||||
- order_by (Optional[List[Dict[str, str]]]): 排序参数列表
|
||||
|
||||
返回:
|
||||
- List[Dict]: 角色详情字典列表
|
||||
"""
|
||||
role_list = await RoleCRUD(auth).get_list_crud(search=search.__dict__, order_by=order_by)
|
||||
return [RoleOutSchema.model_validate(role).model_dump() for role in role_list]
|
||||
|
||||
@classmethod
|
||||
async def create_role_service(cls, auth: AuthSchema, data: RoleCreateSchema) -> Dict:
|
||||
"""创建角色"""
|
||||
"""
|
||||
创建角色
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型
|
||||
- data (RoleCreateSchema): 创建角色模型
|
||||
|
||||
返回:
|
||||
- Dict: 新创建的角色详情字典
|
||||
"""
|
||||
role = await RoleCRUD(auth).get(name=data.name)
|
||||
if role:
|
||||
raise CustomException(msg='创建失败,该角色已存在')
|
||||
@@ -42,7 +70,17 @@ class RoleService:
|
||||
|
||||
@classmethod
|
||||
async def update_role_service(cls, auth: AuthSchema, id: int, data: RoleUpdateSchema) -> Dict:
|
||||
"""更新角色"""
|
||||
"""
|
||||
更新角色
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型
|
||||
- id (int): 角色ID
|
||||
- data (RoleUpdateSchema): 更新角色模型
|
||||
|
||||
返回:
|
||||
- Dict: 更新后的角色详情字典
|
||||
"""
|
||||
role = await RoleCRUD(auth).get_by_id_crud(id=id)
|
||||
if not role:
|
||||
raise CustomException(msg='更新失败,该角色不存在')
|
||||
@@ -54,7 +92,16 @@ class RoleService:
|
||||
|
||||
@classmethod
|
||||
async def delete_role_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
"""删除角色"""
|
||||
"""
|
||||
删除角色
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型
|
||||
- ids (list[int]): 角色ID列表
|
||||
|
||||
返回:
|
||||
- None
|
||||
"""
|
||||
if len(ids) < 1:
|
||||
raise CustomException(msg='删除失败,删除对象不能为空')
|
||||
for id in ids:
|
||||
@@ -65,7 +112,16 @@ class RoleService:
|
||||
|
||||
@classmethod
|
||||
async def set_role_permission_service(cls, auth: AuthSchema, data: RolePermissionSettingSchema) -> None:
|
||||
"""设置角色权限"""
|
||||
"""
|
||||
设置角色权限
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型
|
||||
- data (RolePermissionSettingSchema): 角色权限设置模型
|
||||
|
||||
返回:
|
||||
- None
|
||||
"""
|
||||
# 设置角色菜单权限
|
||||
await RoleCRUD(auth).set_role_menus_crud(role_ids=data.role_ids, menu_ids=data.menu_ids)
|
||||
|
||||
@@ -80,12 +136,29 @@ class RoleService:
|
||||
|
||||
@classmethod
|
||||
async def set_role_available_service(cls, auth: AuthSchema, data: BatchSetAvailable) -> None:
|
||||
"""设置角色可用状态"""
|
||||
"""
|
||||
设置角色可用状态
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型
|
||||
- data (BatchSetAvailable): 批量设置可用状态模型
|
||||
|
||||
返回:
|
||||
- None
|
||||
"""
|
||||
await RoleCRUD(auth).set_available_crud(ids=data.ids, status=data.status)
|
||||
|
||||
@classmethod
|
||||
async def export_role_list_service(cls, role_list: List[Dict[str, Any]]) -> bytes:
|
||||
"""导出角色列表"""
|
||||
"""
|
||||
导出角色列表
|
||||
|
||||
参数:
|
||||
- role_list (List[Dict[str, Any]]): 角色详情字典列表
|
||||
|
||||
返回:
|
||||
- bytes: Excel文件字节流
|
||||
"""
|
||||
# 字段映射配置
|
||||
mapping_dict = {
|
||||
'id': '角色编号',
|
||||
|
||||
Reference in New Issue
Block a user