Added API:/api/mcp/service/resource_group/list/unbind
This commit is contained in:
1 parent
c5854a1d6f
commit
b00fca810d
4 files changed
+40
No files matched your search
@@ -297,6 +297,27 @@ def get_mcp_service_resource_group_list(
|
||||
logger.error(f"Failed to get service simple list: {str(e)}")
|
||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||
|
||||
@router.get("/service/resource_group/list/unbind", summary="Get MCP service's unbind resource group list")
|
||||
def get_mcp_service_unbind_resource_group_list(
|
||||
request: Request,
|
||||
id: str,
|
||||
resource_group_service: ResourceGroupService = Depends(get_resource_group_service),
|
||||
):
|
||||
"""Get paginated list of all MCP services' unbind resource groups."""
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
if not id:
|
||||
return ResponseUtils.error(error_msg=error_msg.MISSING_PARAMETER)
|
||||
try:
|
||||
# Fetch paginated data
|
||||
list = resource_group_service.get_unbind_groups(id)
|
||||
|
||||
return ResponseUtils.success(data=list)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get unbind resource group list: {str(e)}")
|
||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||
|
||||
|
||||
@router.put("/service/resource_group", summary="Bind resource groups to MCP service")
|
||||
def bind_group(
|
||||
request: Request,
|
||||
|
||||
@@ -47,6 +47,10 @@ class ResourceGroupRepository:
|
||||
def get_by_id(self, id: str) -> Optional[ResourceGroup]:
|
||||
return self.db.query(ResourceGroup).filter(ResourceGroup.id == id).first()
|
||||
|
||||
def get_all_not_include(self, ids: List[str]) -> List[ResourceGroup]:
|
||||
"""Get all groups not include in ids"""
|
||||
return self.db.query(ResourceGroup).filter(ResourceGroup.id.not_in(ids)).all()
|
||||
|
||||
def get_all_paginated(self, page: int = 1, page_size: int = 10, keyword: Optional[str] = None) -> Tuple[List[ResourceGroup], int]:
|
||||
offset = (page - 1) * page_size
|
||||
query = self.db.query(ResourceGroup)
|
||||
|
||||
@@ -93,6 +93,9 @@ class ResourceGroupServiceMapRepository:
|
||||
def list_service_ids(self, group_id: str) -> List[str]:
|
||||
return [r.service_id for r in self.db.query(ResourceGroupServiceMap.service_id).filter(ResourceGroupServiceMap.group_id == group_id).all()]
|
||||
|
||||
def list_group_ids(self, service_id: str) -> List[str]:
|
||||
return [r.group_id for r in self.db.query(ResourceGroupServiceMap.group_id).filter(ResourceGroupServiceMap.service_id == service_id).all()]
|
||||
|
||||
def migrate_services(self, from_group_id: str, to_group_id: str, commit: bool = True) -> int:
|
||||
# 过滤已经在新分组的服务
|
||||
existing_services = (
|
||||
|
||||
@@ -335,6 +335,18 @@ class ResourceGroupService:
|
||||
}
|
||||
for s in services
|
||||
]
|
||||
|
||||
def get_unbind_groups(self, sid: str) -> List[dict]:
|
||||
"""Get all groups not bind to service"""
|
||||
gids = self.map_repo.list_group_ids(sid)
|
||||
groups = self.group_repo.get_all_not_include(ids=gids)
|
||||
return [
|
||||
{
|
||||
"id": g.id,
|
||||
"name": g.name,
|
||||
}
|
||||
for g in groups
|
||||
]
|
||||
|
||||
def unbind_service(self, gid: str, sids: List[str]) -> int:
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user