feat: полный patch External Channel архивирование creative в patch и

purchase, удалить у них доп ручки/usecase/dto
This commit is contained in:
Artem Tsyrulnikov
2025-11-11 23:10:08 +03:00
parent f5d2e262f0
commit 552a3ddef2
14 changed files with 80 additions and 117 deletions

View File

@@ -5,7 +5,6 @@ from uuid import UUID
from src import domain
from .creative.archive_creative import archive_creative
from .creative.create_creative import create_creative
from .creative.delete_creative import delete_creative
from .creative.get_creative import get_creative
@@ -15,8 +14,8 @@ from .external_channel.create_external_channel import create_external_channel
from .external_channel.delete_external_channel import delete_external_channel
from .external_channel.get_external_channels import get_external_channels
from .external_channel.import_external_channels_from_excel import import_external_channels_from_excel
from .external_channel.update_external_channel import update_external_channel
from .external_channel.update_external_channel_links import update_external_channel_links
from .purchase.archive_purchase import archive_purchase
from .purchase.create_purchase import create_purchase
from .purchase.delete_purchase import delete_purchase
from .purchase.get_purchase import get_purchase
@@ -78,6 +77,8 @@ class Database(typing.Protocol):
async def delete_external_channel(self, channel_id: UUID) -> None: ...
async def update_external_channel(self, channel: domain.ExternalChannel) -> domain.ExternalChannel: ...
async def get_creative(self, user_id: UUID, creative_id: UUID) -> domain.Creative | None: ...
async def create_creative(self, creative: domain.Creative) -> domain.Creative: ...
@@ -165,19 +166,18 @@ class Usecase:
get_external_channels = get_external_channels
create_external_channel = create_external_channel
delete_external_channel = delete_external_channel
update_external_channel = update_external_channel
update_external_channel_links = update_external_channel_links
import_external_channels_from_excel = import_external_channels_from_excel
get_creatives = get_creatives
get_creative = get_creative
create_creative = create_creative
update_creative = update_creative
archive_creative = archive_creative
delete_creative = delete_creative
get_purchases = get_purchases
get_purchase = get_purchase
create_purchase = create_purchase
update_purchase = update_purchase
archive_purchase = archive_purchase
delete_purchase = delete_purchase
handle_subscription = handle_subscription
fetch_views = fetch_views

View File

@@ -1,32 +0,0 @@
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 archive_creative(self: 'Usecase', creative_id: uuid.UUID, user_id: uuid.UUID) -> dto.CreativeOutput:
async with self.database.transaction():
creative = await self.database.get_creative(user_id, creative_id)
if not creative:
log.warning('User %s attempted to change archive status for unavailable creative %s', user_id, creative_id)
raise domain.CreativeNotFound(creative_id)
creative.status = domain.CreativeStatus.ARCHIVED
updated = await self.database.update_creative(creative)
return dto.CreativeOutput(
id=updated.id,
name=updated.name,
text=updated.text,
target_channel_id=updated.target_channel_id,
target_channel_title=updated.target_channel.title,
created_at=updated.created_at,
status=updated.status,
purchases_count=updated.purchases_count,
)

View File

@@ -23,6 +23,8 @@ async def update_creative(
creative.name = input.name
if input.text is not None:
creative.text = input.text
if input.status is not None:
creative.status = input.status
updated = await self.database.update_creative(creative)

View 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,
)

View File

@@ -1,43 +0,0 @@
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 archive_purchase(self: 'Usecase', purchase_id: uuid.UUID, user_id: uuid.UUID) -> dto.PurchaseOutput:
async with self.database.transaction():
purchase = await self.database.get_purchase(user_id, purchase_id)
if not purchase:
log.warning('Purchase %s not found for user %s', purchase_id, user_id)
raise domain.PurchaseNotFound(purchase_id)
purchase.status = domain.PurchaseStatus.ARCHIVED
updated = await self.database.update_purchase(purchase)
return dto.PurchaseOutput(
id=updated.id,
target_channel_id=updated.target_channel_id,
target_channel_title=updated.target_channel.title,
external_channel_id=updated.external_channel_id,
external_channel_title=updated.external_channel.title,
creative_id=updated.creative_id,
creative_name=updated.creative.name,
placement_date=updated.placement_date,
cost=updated.cost,
comment=updated.comment,
ad_post_url=updated.ad_post_url,
invite_link_type=updated.invite_link_type,
invite_link=updated.invite_link,
status=updated.status,
subscriptions_count=updated.subscriptions_count,
views_count=updated.views_count,
views_availability=updated.views_availability,
last_views_fetch_at=updated.last_views_fetch_at,
created_at=updated.created_at,
)

View File

@@ -28,6 +28,8 @@ async def update_purchase(
purchase.comment = input.comment
if input.ad_post_url is not None:
purchase.ad_post_url = input.ad_post_url
if input.status is not None:
purchase.status = input.status
updated = await self.database.update_purchase(purchase)