33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import logging
|
|
from typing import TYPE_CHECKING
|
|
|
|
from src import domain, dto
|
|
|
|
if TYPE_CHECKING:
|
|
from .. import Usecase
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
async def get_external_channels(self: 'Usecase', input: dto.GetExternalChannelsInput) -> dto.GetExternalChannelsOutput:
|
|
target_channel = await self.database.get_target_channel(input.user_id, channel_id=input.target_channel_id)
|
|
if not target_channel:
|
|
log.warning('Target channel %s not found or not accessible for user %s', input.target_channel_id, input.user_id)
|
|
raise domain.TargetChannelNotFound(input.target_channel_id)
|
|
|
|
channels = await self.database.get_external_channels_for_target(input.target_channel_id)
|
|
|
|
return dto.GetExternalChannelsOutput(
|
|
external_channels=[
|
|
dto.ExternalChannelOutput(
|
|
id=channel.id,
|
|
telegram_id=channel.telegram_id,
|
|
title=channel.title,
|
|
username=channel.username,
|
|
description=channel.description,
|
|
subscribers_count=channel.subscribers_count,
|
|
)
|
|
for channel in channels
|
|
]
|
|
)
|