feat: add workspace
This commit is contained in:
28
src/usecase/workspace/create_workspace.py
Normal file
28
src/usecase/workspace/create_workspace.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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,
|
||||
)
|
||||
Reference in New Issue
Block a user