fix: фиксы после рефакторинга
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import logging
|
||||
import typing
|
||||
import uuid
|
||||
|
||||
@@ -8,6 +9,8 @@ from tortoise.transactions import in_transaction
|
||||
from shared.datebase_base import DatabaseBase
|
||||
from src import domain
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Postgres(DatabaseBase):
|
||||
def transaction(self) -> typing.AsyncContextManager[None]:
|
||||
@@ -89,26 +92,16 @@ class Postgres(DatabaseBase):
|
||||
return await query.first()
|
||||
|
||||
async def get_external_channels_for_target(self, target_channel_id: uuid.UUID) -> list[domain.ExternalChannel]:
|
||||
target = await domain.TargetChannel.filter(id=target_channel_id).prefetch_related('external_channels').first()
|
||||
if not target:
|
||||
return []
|
||||
return await target.external_channels.all()
|
||||
return await domain.ExternalChannel.filter(target_channels__id=target_channel_id).all()
|
||||
|
||||
async def get_user_external_channels(self, user_id: uuid.UUID) -> list[domain.ExternalChannel]:
|
||||
return await domain.ExternalChannel.filter(user_id=user_id).all()
|
||||
|
||||
async def add_external_channel_to_targets(
|
||||
self, external_channel_id: uuid.UUID, target_channel_ids: list[uuid.UUID]
|
||||
self, external_channel: domain.ExternalChannel, target_channel_ids: list[uuid.UUID]
|
||||
) -> None:
|
||||
external_channel = await domain.ExternalChannel.get_or_none(id=external_channel_id)
|
||||
|
||||
if not external_channel:
|
||||
raise ValueError(f'ExternalChannel {external_channel_id} not found')
|
||||
|
||||
for target_id in target_channel_ids:
|
||||
target_channel = await domain.TargetChannel.get_or_none(id=target_id)
|
||||
if target_channel:
|
||||
await external_channel.target_channels.add(target_channel)
|
||||
target_channels = await domain.TargetChannel.filter(id__in=target_channel_ids).all()
|
||||
await external_channel.target_channels.add(*target_channels)
|
||||
|
||||
async def remove_external_channel_from_target(
|
||||
self, external_channel_id: uuid.UUID, target_channel_id: uuid.UUID
|
||||
|
||||
Reference in New Issue
Block a user