feat: пагинация
This commit is contained in:
@@ -11,7 +11,9 @@ if TYPE_CHECKING:
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def get_channel_analytics(self: 'Usecase', input: dto.GetChannelAnalyticsInput) -> dto.GetChannelAnalyticsOutput:
|
||||
async def get_channel_analytics(
|
||||
self: 'Usecase', input: dto.GetChannelAnalyticsInput
|
||||
) -> list[dto.ChannelAnalyticsOutput]:
|
||||
context = await self.ensure_workspace_permission(
|
||||
input.workspace_id, input.user_id, domain.PermissionKey.ANALYTICS_READ
|
||||
)
|
||||
@@ -105,4 +107,4 @@ async def get_channel_analytics(self: 'Usecase', input: dto.GetChannelAnalyticsI
|
||||
)
|
||||
)
|
||||
|
||||
return dto.GetChannelAnalyticsOutput(channels=result)
|
||||
return result
|
||||
|
||||
@@ -13,7 +13,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
async def get_creatives_analytics(
|
||||
self: 'Usecase', input: dto.GetCreativesAnalyticsInput
|
||||
) -> dto.GetCreativesAnalyticsOutput:
|
||||
) -> list[dto.CreativeAnalyticsOutput]:
|
||||
context = await self.ensure_workspace_permission(
|
||||
input.workspace_id, input.user_id, domain.PermissionKey.ANALYTICS_READ
|
||||
)
|
||||
@@ -94,4 +94,4 @@ async def get_creatives_analytics(
|
||||
)
|
||||
)
|
||||
|
||||
return dto.GetCreativesAnalyticsOutput(creatives=result)
|
||||
return result
|
||||
|
||||
@@ -23,7 +23,7 @@ def _calculate_cpm(cost: float | None, views: int | None) -> float | None:
|
||||
|
||||
async def get_placements_analytics(
|
||||
self: 'Usecase', input: dto.GetPlacementsAnalyticsInput
|
||||
) -> dto.GetPlacementsAnalyticsOutput:
|
||||
) -> list[dto.PlacementAnalyticsOutput]:
|
||||
context = await self.ensure_workspace_permission(
|
||||
input.workspace_id, input.user_id, domain.PermissionKey.ANALYTICS_READ
|
||||
)
|
||||
@@ -48,7 +48,7 @@ async def get_placements_analytics(
|
||||
post_ids = [p.post.id for p in placements if p.post]
|
||||
views_map = await self.database.get_latest_views_data_batch(post_ids) if post_ids else {}
|
||||
|
||||
result = [
|
||||
return [
|
||||
dto.PlacementAnalyticsOutput(
|
||||
id=p.id,
|
||||
project_id=p.project_id,
|
||||
@@ -66,5 +66,3 @@ async def get_placements_analytics(
|
||||
)
|
||||
for p in placements
|
||||
]
|
||||
|
||||
return dto.GetPlacementsAnalyticsOutput(placements=result)
|
||||
|
||||
@@ -9,19 +9,17 @@ if TYPE_CHECKING:
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def get_channels(self: 'Usecase', input: dto.GetChannelsInput) -> dto.GetChannelsOutput:
|
||||
async def get_channels(self: 'Usecase', input: dto.GetChannelsInput) -> list[dto.ChannelOutput]:
|
||||
channels = await self.database.search_channels(username_query=input.username)
|
||||
|
||||
log.debug('Found %s channels for username query: %s', len(channels), input.username)
|
||||
|
||||
return dto.GetChannelsOutput(
|
||||
channels=[
|
||||
dto.ChannelOutput(
|
||||
id=channel.id,
|
||||
telegram_id=channel.telegram_id,
|
||||
title=channel.title,
|
||||
username=channel.username,
|
||||
)
|
||||
for channel in channels
|
||||
]
|
||||
)
|
||||
return [
|
||||
dto.ChannelOutput(
|
||||
id=channel.id,
|
||||
telegram_id=channel.telegram_id,
|
||||
title=channel.title,
|
||||
username=channel.username,
|
||||
)
|
||||
for channel in channels
|
||||
]
|
||||
|
||||
@@ -6,7 +6,7 @@ if TYPE_CHECKING:
|
||||
from .. import Usecase
|
||||
|
||||
|
||||
async def get_creatives(self: 'Usecase', input: dto.GetCreativesInput) -> dto.GetCreativesOutput:
|
||||
async def get_creatives(self: 'Usecase', input: dto.GetCreativesInput) -> list[dto.CreativeOutput]:
|
||||
context = await self.ensure_workspace_permission(
|
||||
input.workspace_id, input.user_id, domain.PermissionKey.PROJECTS_READ
|
||||
)
|
||||
@@ -24,18 +24,16 @@ async def get_creatives(self: 'Usecase', input: dto.GetCreativesInput) -> dto.Ge
|
||||
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
|
||||
]
|
||||
)
|
||||
return [
|
||||
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
|
||||
]
|
||||
|
||||
@@ -8,7 +8,7 @@ if TYPE_CHECKING:
|
||||
from .. import Usecase
|
||||
|
||||
|
||||
async def get_placements(self: 'Usecase', input: dto.GetPlacementsInput) -> dto.GetPlacementsOutput:
|
||||
async def get_placements(self: 'Usecase', input: dto.GetPlacementsInput) -> list[dto.PlacementOutput]:
|
||||
context = await self.ensure_workspace_permission(
|
||||
input.workspace_id, input.user_id, domain.PermissionKey.PLACEMENTS_READ
|
||||
)
|
||||
@@ -56,4 +56,4 @@ async def get_placements(self: 'Usecase', input: dto.GetPlacementsInput) -> dto.
|
||||
)
|
||||
)
|
||||
|
||||
return dto.GetPlacementsOutput(placements=placement_outputs)
|
||||
return placement_outputs
|
||||
|
||||
@@ -8,7 +8,7 @@ if TYPE_CHECKING:
|
||||
|
||||
async def get_workspace_projects(
|
||||
self: 'Usecase', input: dto.GetWorkspaceProjectsInput
|
||||
) -> dto.GetWorkspaceProjectsOutput:
|
||||
) -> list[dto.ProjectOutput]:
|
||||
context = await self.ensure_workspace_permission(
|
||||
input.workspace_id, input.user_id, domain.PermissionKey.PROJECTS_READ
|
||||
)
|
||||
@@ -17,15 +17,13 @@ async def get_workspace_projects(
|
||||
|
||||
projects = await self.database.get_workspace_projects(input.workspace_id, allowed_project_ids=allowed_project_ids)
|
||||
|
||||
return dto.GetWorkspaceProjectsOutput(
|
||||
projects=[
|
||||
dto.ProjectOutput(
|
||||
id=project.id,
|
||||
telegram_id=project.channel.telegram_id,
|
||||
title=project.channel.title,
|
||||
username=project.channel.username,
|
||||
status=project.status,
|
||||
)
|
||||
for project in projects
|
||||
]
|
||||
)
|
||||
return [
|
||||
dto.ProjectOutput(
|
||||
id=project.id,
|
||||
telegram_id=project.channel.telegram_id,
|
||||
title=project.channel.title,
|
||||
username=project.channel.username,
|
||||
status=project.status,
|
||||
)
|
||||
for project in projects
|
||||
]
|
||||
|
||||
@@ -11,7 +11,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
async def get_purchase_plan_channels(
|
||||
self: 'Usecase', input: dto.GetPurchasePlanChannelsInput
|
||||
) -> dto.GetPurchasePlanChannelsOutput:
|
||||
) -> list[dto.PurchasePlanChannelOutput]:
|
||||
context = await self.ensure_workspace_permission(
|
||||
input.workspace_id, input.user_id, domain.PermissionKey.PLACEMENTS_READ
|
||||
)
|
||||
@@ -27,20 +27,18 @@ async def get_purchase_plan_channels(
|
||||
plan_channels = await self.database.get_purchase_plan_channels(plan.id)
|
||||
log.debug('Fetched %s channels for purchase plan %s (project %s)', len(plan_channels), plan.id, project.id)
|
||||
|
||||
return dto.GetPurchasePlanChannelsOutput(
|
||||
channels=[
|
||||
dto.PurchasePlanChannelOutput(
|
||||
id=plan_channel.id,
|
||||
status=plan_channel.status,
|
||||
planned_cost=plan_channel.planned_cost,
|
||||
comment=plan_channel.comment,
|
||||
channel=dto.ChannelOutput(
|
||||
id=plan_channel.channel.id,
|
||||
telegram_id=plan_channel.channel.telegram_id,
|
||||
title=plan_channel.channel.title,
|
||||
username=plan_channel.channel.username,
|
||||
),
|
||||
)
|
||||
for plan_channel in plan_channels
|
||||
]
|
||||
)
|
||||
return [
|
||||
dto.PurchasePlanChannelOutput(
|
||||
id=plan_channel.id,
|
||||
status=plan_channel.status,
|
||||
planned_cost=plan_channel.planned_cost,
|
||||
comment=plan_channel.comment,
|
||||
channel=dto.ChannelOutput(
|
||||
id=plan_channel.channel.id,
|
||||
telegram_id=plan_channel.channel.telegram_id,
|
||||
title=plan_channel.channel.title,
|
||||
username=plan_channel.channel.username,
|
||||
),
|
||||
)
|
||||
for plan_channel in plan_channels
|
||||
]
|
||||
|
||||
@@ -9,7 +9,7 @@ if TYPE_CHECKING:
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def get_views_history(self: 'Usecase', input: dto.GetViewsHistoryInput) -> dto.GetViewsHistoryOutput:
|
||||
async def get_views_history(self: 'Usecase', input: dto.GetViewsHistoryInput) -> list[dto.PostViewsHistoryOutput]:
|
||||
context = await self.ensure_workspace_permission(
|
||||
input.workspace_id, input.user_id, domain.PermissionKey.PLACEMENTS_READ
|
||||
)
|
||||
@@ -22,7 +22,7 @@ async def get_views_history(self: 'Usecase', input: dto.GetViewsHistoryInput) ->
|
||||
context.ensure_project_permission(domain.PermissionKey.PLACEMENTS_READ, placement.project_id)
|
||||
|
||||
if not placement.post:
|
||||
return dto.GetViewsHistoryOutput(histories=[])
|
||||
return []
|
||||
|
||||
histories = await self.database.get_views_history(
|
||||
placement.post.id,
|
||||
@@ -30,15 +30,13 @@ async def get_views_history(self: 'Usecase', input: dto.GetViewsHistoryInput) ->
|
||||
to_date=input.to_date,
|
||||
)
|
||||
|
||||
return dto.GetViewsHistoryOutput(
|
||||
histories=[
|
||||
dto.PostViewsHistoryOutput(
|
||||
id=history.id,
|
||||
post_id=history.post_id,
|
||||
views_count=history.views_count,
|
||||
fetched_at=history.fetched_at,
|
||||
created_at=history.created_at,
|
||||
)
|
||||
for history in histories
|
||||
]
|
||||
)
|
||||
return [
|
||||
dto.PostViewsHistoryOutput(
|
||||
id=history.id,
|
||||
post_id=history.post_id,
|
||||
views_count=history.views_count,
|
||||
fetched_at=history.fetched_at,
|
||||
created_at=history.created_at,
|
||||
)
|
||||
for history in histories
|
||||
]
|
||||
|
||||
@@ -12,9 +12,9 @@ if TYPE_CHECKING:
|
||||
|
||||
async def get_workspace_invites(
|
||||
self: Usecase, workspace_id: uuid.UUID, user_id: uuid.UUID
|
||||
) -> dto.GetWorkspaceInvitesOutput:
|
||||
) -> list[dto.WorkspaceInviteOutput]:
|
||||
await self.ensure_workspace_permission(workspace_id, user_id, domain.PermissionKey.ADMIN_FULL)
|
||||
|
||||
invites = await self.database.get_workspace_invites(workspace_id)
|
||||
|
||||
return dto.GetWorkspaceInvitesOutput(invites=[workspace_invite_to_dto(invite) for invite in invites])
|
||||
return [workspace_invite_to_dto(invite) for invite in invites]
|
||||
|
||||
@@ -12,9 +12,9 @@ if TYPE_CHECKING:
|
||||
|
||||
async def get_workspace_members(
|
||||
self: Usecase, workspace_id: uuid.UUID, user_id: uuid.UUID
|
||||
) -> dto.GetWorkspaceMembersOutput:
|
||||
) -> list[dto.WorkspaceMemberOutput]:
|
||||
await self.ensure_workspace_permission(workspace_id, user_id, domain.PermissionKey.ADMIN_FULL)
|
||||
|
||||
members = await self.database.get_workspace_members(workspace_id)
|
||||
|
||||
return dto.GetWorkspaceMembersOutput(members=[workspace_member_to_dto(member) for member in members])
|
||||
return [workspace_member_to_dto(member) for member in members]
|
||||
|
||||
@@ -7,15 +7,13 @@ if TYPE_CHECKING:
|
||||
from .. import Usecase
|
||||
|
||||
|
||||
async def get_workspaces(self: 'Usecase', user_id: uuid.UUID) -> dto.GetWorkspacesOutput:
|
||||
async def get_workspaces(self: 'Usecase', user_id: uuid.UUID) -> list[dto.WorkspaceMembershipOutput]:
|
||||
memberships = await self.database.get_user_workspaces(user_id)
|
||||
|
||||
return dto.GetWorkspacesOutput(
|
||||
workspaces=[
|
||||
dto.WorkspaceMembershipOutput(
|
||||
id=membership.workspace_id,
|
||||
name=membership.workspace.name,
|
||||
)
|
||||
for membership in memberships
|
||||
]
|
||||
)
|
||||
return [
|
||||
dto.WorkspaceMembershipOutput(
|
||||
id=membership.workspace_id,
|
||||
name=membership.workspace.name,
|
||||
)
|
||||
for membership in memberships
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user