размещения ручки
This commit is contained in:
@@ -40,6 +40,7 @@ def _build_placement_output(placement: domain.Placement) -> dto.PlacementOutput:
|
||||
return dto.PlacementOutput(
|
||||
id=placement.id,
|
||||
status=placement.status,
|
||||
creative_id=placement.creative_id,
|
||||
comment=placement.comment,
|
||||
invite_link=placement.invite_link,
|
||||
invite_link_type=placement.invite_link_type,
|
||||
@@ -69,18 +70,13 @@ async def create_placements(
|
||||
|
||||
context.ensure_project_permission(domain.PermissionKey.PLACEMENTS_WRITE, project.id)
|
||||
|
||||
creative = await self.database.get_creative(workspace_id, input.creative_id)
|
||||
if not creative or creative.project_id != project.id:
|
||||
raise domain.CreativeNotFound(input.creative_id)
|
||||
|
||||
if project.channel.telegram_id is None:
|
||||
raise domain.ChannelNotFound(project.channel.id)
|
||||
|
||||
invite_link_type = project.purchase_invite_type_default
|
||||
requires_approval = invite_link_type == domain.InviteLinkType.APPROVAL
|
||||
|
||||
details = input.details
|
||||
placements: list[domain.Placement] = []
|
||||
creatives_by_id: dict[uuid.UUID, domain.Creative] = {}
|
||||
|
||||
for channel_input in input.channels:
|
||||
channel = await self.database.get_channel(username=channel_input.username)
|
||||
@@ -98,23 +94,26 @@ async def create_placements(
|
||||
await self.database.create_channel(channel)
|
||||
log.info('Created channel @%s with telegram_id=%s', channel.username, channel.telegram_id)
|
||||
|
||||
invite_link = await self.telegram_bot.create_chat_invite_link(project.channel.telegram_id, requires_approval)
|
||||
log.info(
|
||||
'Created invite link for placement channel_telegram_id=%s requires_approval=%s invite_link=%s',
|
||||
project.channel.telegram_id,
|
||||
requires_approval,
|
||||
invite_link,
|
||||
)
|
||||
|
||||
# Объединяем общие детали с деталями конкретного канала
|
||||
channel_details = channel_input.details
|
||||
creative_id = (
|
||||
channel_details.creative_id if channel_details and channel_details.creative_id else None
|
||||
) or (details.creative_id if details and details.creative_id else None) or input.creative_id
|
||||
if not creative_id:
|
||||
raise domain.CreativeNotFound()
|
||||
creative = creatives_by_id.get(creative_id)
|
||||
if not creative:
|
||||
creative = await self.database.get_creative(workspace_id, creative_id)
|
||||
if not creative or creative.project_id != project.id:
|
||||
raise domain.CreativeNotFound(creative_id)
|
||||
creatives_by_id[creative_id] = creative
|
||||
placement = domain.Placement(
|
||||
project_id=project.id,
|
||||
creative_id=creative.id,
|
||||
channel_id=channel.id,
|
||||
invite_link=invite_link,
|
||||
invite_link=None,
|
||||
invite_link_type=invite_link_type,
|
||||
status=channel_input.status or domain.PlacementStatus.PLANNED,
|
||||
status=channel_input.status or domain.PlacementStatus.NO_STATUS,
|
||||
comment=channel_input.comment,
|
||||
# Приоритет: channel details > общие details
|
||||
placement_at=(channel_details.placement_at if channel_details else None)
|
||||
@@ -135,10 +134,10 @@ async def create_placements(
|
||||
placements.append(placement)
|
||||
|
||||
log.info(
|
||||
'Created %s placements for project %s (creative %s)',
|
||||
'Created %s placements for project %s (creatives %s)',
|
||||
len(placements),
|
||||
project.id,
|
||||
creative.id,
|
||||
list(creatives_by_id.keys()),
|
||||
)
|
||||
|
||||
placement_outputs = []
|
||||
@@ -147,7 +146,7 @@ async def create_placements(
|
||||
placement_outputs.append(
|
||||
dto.PlacementWithPostsOutput(
|
||||
**placement_output.model_dump(),
|
||||
placement_posts=[],
|
||||
placement_post=None,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user