42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from typing import TYPE_CHECKING
|
|
|
|
from src import domain, dto
|
|
|
|
if TYPE_CHECKING:
|
|
from .. import Usecase
|
|
|
|
|
|
async def get_creatives(self: 'Usecase', input: dto.GetCreativesInput) -> dto.GetCreativesOutput:
|
|
context = await self.ensure_workspace_permission(
|
|
input.workspace_id, input.user_id, domain.PermissionKey.PROJECTS_READ
|
|
)
|
|
|
|
allowed_project_ids = context.allowed_project_ids(domain.PermissionKey.PROJECTS_READ)
|
|
|
|
if input.project_id is not None:
|
|
context.ensure_project_permission(domain.PermissionKey.PROJECTS_READ, input.project_id)
|
|
allowed_project_ids = None
|
|
|
|
creatives = await self.database.get_workspace_creatives(
|
|
input.workspace_id,
|
|
input.project_id,
|
|
input.include_archived,
|
|
allowed_project_ids=allowed_project_ids,
|
|
)
|
|
|
|
return dto.GetCreativesOutput(
|
|
creatives=[
|
|
dto.CreativeOutput(
|
|
id=creative.id,
|
|
name=creative.name,
|
|
text=creative.text,
|
|
project_id=creative.project_id,
|
|
project_channel_title=creative.project.channel.title,
|
|
created_at=creative.created_at,
|
|
status=creative.status,
|
|
placements_count=creative.placements_count,
|
|
)
|
|
for creative in creatives
|
|
]
|
|
)
|