diff --git a/api/manage_tanant.py b/api/manage_tanant.py index 595a0e3..1178120 100644 --- a/api/manage_tanant.py +++ b/api/manage_tanant.py @@ -13,10 +13,10 @@ from fastapi import HTTPException, Response from models import Tenant, User # 假设你已导入 Tenant 和 User 模型 from dependencies import SessionDep # 假设 SessionDep 是数据库会话的依赖 -#列举所有租户 + +# 列举所有租户 @router.get("/api/s1/tenant") async def get_tenant(response: Response, session: SessionDep, current_user: User = Depends(get_current_user)): - if current_user.role != 0: raise HTTPException(status_code=403, detail="Only Superadmin can list all tenants.") @@ -43,6 +43,7 @@ async def get_tenant(response: Response, session: SessionDep, current_user: User return {"tenants": tenant_data} + # 新增和修改租户 @router.post("/api/s1/tenant") async def create_or_update_tenant(data: dict, session: SessionDep, current_user: User = Depends(get_current_user)): @@ -101,19 +102,19 @@ async def create_or_update_tenant(data: dict, session: SessionDep, current_user: user = session.exec(user_query).first() - #如果找不到对应的用户,抛出错误 + # 如果找不到对应的用户,抛出错误 if not user: raise HTTPException(status_code=404, detail="User not found") user.password = password session.add(user) session.commit() - print(user) #测试用 + print(user) # 测试用 return {"message": "Tenant and User update successfully"} -#删除租户 + +# 删除租户 @router.delete("/api/s1/tenant") async def delete_tenant(data: dict, session: SessionDep, current_user: User = Depends(get_current_user)): - if current_user.role != 0: raise HTTPException(status_code=403, detail="Only Superadmin can delete tenants.") @@ -136,4 +137,4 @@ async def delete_tenant(data: dict, session: SessionDep, current_user: User = De session.delete(tenant) session.commit() - return {"detail": "Tenant deleted successfully"} \ No newline at end of file + return {"detail": "Tenant deleted successfully"} diff --git a/requirements.txt b/requirements.txt index c3442d3..7290373 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ uvicorn~=0.32.0 pydantic~=2.9.2 pydantic-settings~=2.6.1 mysqlclient -sqlmodel~=0.0.22 \ No newline at end of file +sqlmodel~=0.0.22 +sqlalchemy~=2.0.36 \ No newline at end of file