feat: полный patch External Channel архивирование creative в patch и
purchase, удалить у них доп ручки/usecase/dto
This commit is contained in:
42
src/usecase/external_channel/update_external_channel.py
Normal file
42
src/usecase/external_channel/update_external_channel.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import logging
|
||||
import uuid
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from src import domain, dto
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .. import Usecase
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def update_external_channel(
|
||||
self: 'Usecase', channel_id: uuid.UUID, input: dto.UpdateExternalChannelInput, user_id: uuid.UUID
|
||||
) -> dto.ExternalChannelOutput:
|
||||
async with self.database.transaction():
|
||||
external_channel = await self.database.get_external_channel(user_id, channel_id=channel_id)
|
||||
if not external_channel:
|
||||
log.warning('External channel %s not found', channel_id)
|
||||
raise domain.ExternalChannelNotFound(channel_id)
|
||||
|
||||
if input.title is not None:
|
||||
external_channel.title = input.title
|
||||
if input.username is not None:
|
||||
external_channel.username = input.username
|
||||
if input.description is not None:
|
||||
external_channel.description = input.description
|
||||
if input.subscribers_count is not None:
|
||||
external_channel.subscribers_count = input.subscribers_count
|
||||
|
||||
updated = await self.database.update_external_channel(external_channel)
|
||||
|
||||
log.info('External channel %s updated', channel_id)
|
||||
|
||||
return dto.ExternalChannelOutput(
|
||||
id=updated.id,
|
||||
telegram_id=updated.telegram_id,
|
||||
title=updated.title,
|
||||
username=updated.username,
|
||||
description=updated.description,
|
||||
subscribers_count=updated.subscribers_count,
|
||||
)
|
||||
Reference in New Issue
Block a user