ref: рефакторинг usecases
This commit is contained in:
@@ -11,31 +11,28 @@ 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)
|
||||
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,
|
||||
status=domain.CreativeStatus.ACTIVE,
|
||||
target_channel_id=target_channel.id,
|
||||
user_id=user_id,
|
||||
)
|
||||
creative = domain.Creative(
|
||||
name=input.name,
|
||||
text=input.text,
|
||||
status=domain.CreativeStatus.ACTIVE,
|
||||
target_channel_id=target_channel.id,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
created = await self.database.create_creative(creative)
|
||||
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,
|
||||
placements_count=created.placements_count,
|
||||
)
|
||||
return dto.CreativeOutput(
|
||||
id=creative.id,
|
||||
name=creative.name,
|
||||
text=creative.text,
|
||||
target_channel_id=target_channel.id,
|
||||
target_channel_title=target_channel.title,
|
||||
created_at=creative.created_at,
|
||||
status=creative.status,
|
||||
placements_count=creative.placements_count,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user