refactor
This commit is contained in:
@@ -14,18 +14,22 @@ async def get_views_history(self: 'Usecase', input: dto.GetViewsHistoryInput) ->
|
||||
input.workspace_id, input.user_id, domain.PermissionKey.PLACEMENTS_READ
|
||||
)
|
||||
|
||||
placement = await self.database.get_placement(input.workspace_id, input.placement_id)
|
||||
if not placement:
|
||||
log.warning('Placement %s not found for user %s', input.placement_id, input.user_id)
|
||||
raise domain.PlacementNotFound(input.placement_id)
|
||||
publication = await self.database.get_publication(input.workspace_id, input.publication_id)
|
||||
if not publication:
|
||||
log.warning('Publication %s not found for user %s', input.publication_id, input.user_id)
|
||||
raise domain.PublicationNotFound(input.publication_id)
|
||||
|
||||
context.ensure_project_permission(domain.PermissionKey.PLACEMENTS_READ, placement.project_id)
|
||||
if not publication.placement:
|
||||
log.error('Publication %s has no placement', publication.id)
|
||||
raise domain.PlacementNotFound(publication.placement_id)
|
||||
|
||||
if not placement.post:
|
||||
context.ensure_project_permission(domain.PermissionKey.PLACEMENTS_READ, publication.placement.project_id)
|
||||
|
||||
if not publication.post:
|
||||
return []
|
||||
|
||||
histories = await self.database.get_views_history(
|
||||
placement.post.id,
|
||||
publication.post.id,
|
||||
from_date=input.from_date,
|
||||
to_date=input.to_date,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user