feat: add workspace

This commit is contained in:
Artem Tsyrulnikov
2025-12-13 22:09:55 +03:00
parent 2fdd56c3e0
commit af32e2a507
55 changed files with 677 additions and 227 deletions

View File

@@ -22,6 +22,7 @@ from .creative.get_creative import get_creative
from .creative.get_creatives import get_creatives
from .creative.handle_creative_callback import handle_creative_callback
from .creative.handle_creative_text_input import handle_creative_text_input
from .creative.handle_creative_workspace_callback import handle_creative_workspace_callback
from .creative.start_creative_creation import start_creative_creation
from .creative.update_creative import update_creative
from .external_channel.create_external_channel import create_external_channel
@@ -41,7 +42,10 @@ from .target_channel.disconnect_target_chan_by_tg_id import disconnect_target_ch
from .target_channel.get_user_target_chans import get_user_target_chans
from .target_channel.update_target_chan_permissions import update_target_chan_permissions
from .views.get_views_history import get_views_history
from .views.update_views_manually import update_views_manually
from .workspace.create_workspace import create_workspace
from .workspace.delete_workspace import delete_workspace
from .workspace.get_workspaces import get_workspaces
from .workspace.update_workspace import update_workspace
class Database(typing.Protocol):
@@ -51,6 +55,24 @@ class Database(typing.Protocol):
async def create_user(self, user: domain.User) -> None: ...
async def create_workspace(self, workspace: domain.Workspace) -> None: ...
async def update_workspace(self, workspace: domain.Workspace) -> None: ...
async def delete_workspace(self, workspace_id: UUID) -> None: ...
async def add_user_to_workspace(self, workspace_id: UUID, user_id: UUID) -> None: ...
async def get_user_workspaces(self, user_id: UUID) -> list[domain.WorkspaceUser]: ...
async def get_workspace(self, workspace_id: UUID) -> domain.Workspace | None: ...
async def get_workspace_for_user(self, workspace_id: UUID, user_id: UUID) -> domain.Workspace | None: ...
async def get_default_workspace_for_user(self, user_id: UUID) -> domain.Workspace | None: ...
async def get_workspace_membership(self, workspace_id: UUID, user_id: UUID) -> domain.WorkspaceUser | None: ...
async def create_login_token(self, login_token: domain.LoginToken) -> None: ...
async def create_creative(self, creative: domain.Creative) -> None: ...
@@ -60,24 +82,28 @@ class Database(typing.Protocol):
async def mark_token_as_used(self, token: str) -> None: ...
async def get_target_channel(
self, user_id: UUID, channel_id: UUID | None = None, telegram_id: int | None = None
self, workspace_id: UUID, channel_id: UUID | None = None, telegram_id: int | None = None
) -> domain.TargetChannel | None: ...
async def get_target_channel_for_user_by_telegram(
self, user_id: UUID, telegram_id: int
) -> domain.TargetChannel | None: ...
async def upsert_target_channel(self, channel: domain.TargetChannel) -> None: ...
async def get_user_target_channels(self, user_id: UUID) -> list[domain.TargetChannel]: ...
async def get_workspace_target_channels(self, workspace_id: UUID) -> list[domain.TargetChannel]: ...
async def update_target_channel(self, channel: domain.TargetChannel) -> None: ...
async def get_external_channel(
self, user_id: UUID, channel_id: UUID | None = None, telegram_id: int | None = None
self, workspace_id: UUID, channel_id: UUID | None = None, telegram_id: int | None = None
) -> domain.ExternalChannel | None: ...
async def create_external_channel(self, channel: domain.ExternalChannel) -> None: ...
async def get_external_channels_for_target(self, target_channel_id: UUID) -> list[domain.ExternalChannel]: ...
async def get_user_external_channels(self, user_id: UUID) -> list[domain.ExternalChannel]: ...
async def get_workspace_external_channels(self, workspace_id: UUID) -> list[domain.ExternalChannel]: ...
async def add_external_channel_to_targets(
self, external_channel: domain.ExternalChannel, target_channel_ids: list[UUID]
@@ -89,25 +115,25 @@ class Database(typing.Protocol):
async def update_external_channel(self, channel: domain.ExternalChannel) -> None: ...
async def get_creative(self, user_id: UUID, creative_id: UUID) -> domain.Creative | None: ...
async def get_creative(self, workspace_id: UUID, creative_id: UUID) -> domain.Creative | None: ...
async def update_creative(self, creative: domain.Creative) -> None: ...
async def get_user_creatives(
self, user_id: UUID, target_channel_id: UUID | None = None, include_archived: bool = False
async def get_workspace_creatives(
self, workspace_id: UUID, target_channel_id: UUID | None = None, include_archived: bool = False
) -> list[domain.Creative]: ...
async def delete_creative(self, creative_id: UUID) -> None: ...
async def get_placement(self, user_id: UUID, placement_id: UUID) -> domain.Placement | None: ...
async def get_placement(self, workspace_id: UUID, placement_id: UUID) -> domain.Placement | None: ...
async def create_placement(self, placement: domain.Placement) -> None: ...
async def update_placement(self, placement: domain.Placement) -> None: ...
async def get_user_placements(
async def get_workspace_placements(
self,
user_id: UUID,
workspace_id: UUID,
target_channel_id: UUID | None = None,
external_channel_id: UUID | None = None,
creative_id: UUID | None = None,
@@ -181,6 +207,13 @@ class Usecase:
telegram_bot: TelegramBotWriter
jwt_encoder: JWTEncoder
async def ensure_workspace_access(self, workspace_id: UUID, user_id: UUID) -> domain.Workspace:
workspace = await self.database.get_workspace_for_user(workspace_id, user_id)
if not workspace:
raise domain.WorkspaceNotFound(workspace_id)
return workspace
validate_login_token = validate_login_token
telegram_login = telegram_login
telegram_start = telegram_start
@@ -201,6 +234,7 @@ class Usecase:
delete_creative = delete_creative
start_creative_creation = start_creative_creation
handle_creative_callback = handle_creative_callback
handle_creative_workspace_callback = handle_creative_workspace_callback
handle_creative_text_input = handle_creative_text_input
get_placements = get_placements
get_placement = get_placement
@@ -210,8 +244,11 @@ class Usecase:
handle_subscription = handle_subscription
handle_unsubscription = handle_unsubscription
get_views_history = get_views_history
update_views_manually = update_views_manually
get_placements_analytics = get_placements_analytics
get_creatives_analytics = get_creatives_analytics
get_external_channels_analytics = get_external_channels_analytics
get_spending_analytics = get_spending_analytics
get_workspaces = get_workspaces
create_workspace = create_workspace
update_workspace = update_workspace
delete_workspace = delete_workspace