29 lines
711 B
Python
29 lines
711 B
Python
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)
|
|
await self.database.add_user_to_workspace(workspace.id, user_id)
|
|
|
|
return dto.CreateWorkspaceOutput(
|
|
id=workspace.id,
|
|
name=workspace.name,
|
|
)
|