new telegram bot

This commit is contained in:
Artem Tsyrulnikov
2025-12-28 15:50:06 +03:00
parent 69179c64be
commit 2fb8c83041
75 changed files with 3719 additions and 1046 deletions

View File

@@ -0,0 +1,52 @@
import logging
from typing import TYPE_CHECKING
from fastapi import HTTPException
from src import domain, dto
if TYPE_CHECKING:
from .. import Usecase
log = logging.getLogger(__name__)
async def attach_channel_to_workspace(
self: 'Usecase', input: dto.AttachChannelToWorkspaceInput
) -> dto.ProjectOutput:
"""Привязать канал к workspace (вызывается из Golang бота после выбора workspace пользователем)"""
channel = await self.database.get_channel(channel_id=input.channel_id)
if not channel:
raise HTTPException(status_code=404, detail='Channel not found')
workspace = await self.database.get_workspace(input.workspace_id)
if not workspace:
raise HTTPException(status_code=404, detail='Workspace not found')
# Проверяем что проект еще не существует
project = await self.database.get_project(workspace.id, channel_id=channel.id)
if project:
# Проект уже существует - просто активируем
project.status = domain.ProjectStatus.ACTIVE
await self.database.update_project(project)
log.info('Project %s reactivated in workspace %s', project.id, workspace.id)
else:
# Создаем новый проект
project = domain.Project(
workspace_id=workspace.id,
channel_id=channel.id,
status=domain.ProjectStatus.ACTIVE,
)
await self.database.create_project(project)
log.info('Project created for channel %s in workspace %s', channel.id, workspace.id)
await self.ensure_active_purchase_plan(project)
return dto.ProjectOutput(
id=project.id,
telegram_id=channel.telegram_id,
title=channel.title,
username=channel.username,
status=project.status,
)