feat: creatives and external channels
This commit is contained in:
40
src/usecase/creative/create_creative.py
Normal file
40
src/usecase/creative/create_creative.py
Normal file
@@ -0,0 +1,40 @@
|
||||
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 create_creative(self: 'Usecase', input: dto.CreateCreativeInput, user_id: uuid.UUID) -> dto.CreativeOutput:
|
||||
async with self.database.transaction():
|
||||
target_channel = await self.database.get_target_channel(user_id, channel_id=input.target_channel_id)
|
||||
if not target_channel:
|
||||
log.warning(
|
||||
'User %s attempted to create creative for unavailable target %s', user_id, input.target_channel_id
|
||||
)
|
||||
raise domain.TargetChannelNotFound(input.target_channel_id)
|
||||
|
||||
creative = domain.Creative(
|
||||
name=input.name,
|
||||
text=input.text,
|
||||
target_channel_id=target_channel.id,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
created = await self.database.create_creative(creative)
|
||||
|
||||
return dto.CreativeOutput(
|
||||
id=created.id,
|
||||
name=created.name,
|
||||
text=created.text,
|
||||
target_channel_id=created.target_channel_id,
|
||||
target_channel_title=created.target_channel.title,
|
||||
created_at=created.created_at,
|
||||
status=created.status,
|
||||
purchases_count=created.purchases_count,
|
||||
)
|
||||
Reference in New Issue
Block a user