mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 20:55:14 +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): 完善工具函数的文档字符串
97 lines
2.8 KiB
Python
97 lines
2.8 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.auth.schema import AuthSchema
|
|
from .model import McpModel
|
|
from .schema import McpCreateSchema, McpUpdateSchema
|
|
|
|
|
|
class McpCRUD(CRUDBase[McpModel, McpCreateSchema, McpUpdateSchema]):
|
|
"""MCP 服务器数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
"""
|
|
初始化CRUD
|
|
|
|
参数:
|
|
- auth (AuthSchema): 认证信息模型
|
|
"""
|
|
self.auth = auth
|
|
super().__init__(model=McpModel, auth=auth)
|
|
|
|
async def get_by_id_crud(self, id: int) -> Optional[McpModel]:
|
|
"""
|
|
获取MCP服务器详情
|
|
|
|
参数:
|
|
- id (int): MCP服务器ID
|
|
|
|
返回:
|
|
- Optional[McpModel]: MCP服务器模型实例(如果存在)
|
|
"""
|
|
return await self.get(id=id)
|
|
|
|
async def get_by_name_crud(self, name: str) -> Optional[McpModel]:
|
|
"""
|
|
通过名称获取MCP服务器
|
|
|
|
参数:
|
|
- name (str): MCP服务器名称
|
|
|
|
返回:
|
|
- Optional[McpModel]: MCP服务器模型实例(如果存在)
|
|
"""
|
|
return await self.get(name=name)
|
|
|
|
async def get_list_crud(self, search: Optional[Dict] = None, order_by: Optional[List[Dict[str, str]]] = None) -> Sequence[McpModel]:
|
|
"""
|
|
列表查询MCP服务器
|
|
|
|
参数:
|
|
- search (Optional[Dict]): 查询参数字典
|
|
- order_by (Optional[List[Dict[str, str]]]): 排序参数列表
|
|
|
|
返回:
|
|
- Sequence[McpModel]: MCP服务器模型实例序列
|
|
"""
|
|
return await self.list(search=search or {}, order_by=order_by or [{'id': 'asc'}])
|
|
|
|
async def create_crud(self, data: McpCreateSchema) -> Optional[McpModel]:
|
|
"""
|
|
创建MCP服务器
|
|
|
|
参数:
|
|
- data (McpCreateSchema): 创建MCP服务器模型
|
|
|
|
返回:
|
|
- Optional[McpModel]: 创建的MCP服务器模型实例(如果成功)
|
|
"""
|
|
return await self.create(data=data)
|
|
|
|
async def update_crud(self, id: int, data: McpUpdateSchema) -> Optional[McpModel]:
|
|
"""
|
|
更新MCP服务器
|
|
|
|
参数:
|
|
- id (int): MCP服务器ID
|
|
- data (McpUpdateSchema): 更新MCP服务器模型
|
|
|
|
返回:
|
|
- Optional[McpModel]: 更新的MCP服务器模型实例(如果成功)
|
|
"""
|
|
return await self.update(id=id, data=data)
|
|
|
|
async def delete_crud(self, ids: List[int]) -> None:
|
|
"""
|
|
批量删除MCP服务器
|
|
|
|
参数:
|
|
- ids (List[int]): MCP服务器ID列表
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
return await self.delete(ids=ids)
|