import uuid from typing import TYPE_CHECKING from src import domain, dto if TYPE_CHECKING: from .. import Usecase async def create_workspace( self: 'Usecase', user_id: uuid.UUID, input: dto.CreateWorkspaceInput ) -> dto.CreateWorkspaceOutput: user = await self.database.get_user(user_id=user_id) if not user: raise domain.UserNotFound(user_id) workspace = domain.Workspace( name=input.name, ) async with self.database.transaction(): await self.database.create_workspace(workspace) membership = await self.database.add_user_to_workspace(workspace.id, user_id) await self.database.set_workspace_user_permissions( membership.id, global_permissions={domain.PermissionKey.ADMIN_FULL}, scoped_permissions=[], ) return dto.CreateWorkspaceOutput( id=workspace.id, name=workspace.name, )