feat: add analytics overview endpoint
This commit is contained in:
@@ -388,6 +388,8 @@ class Postgres(DatabaseBase, Database):
|
||||
creative_id: uuid.UUID | None = None,
|
||||
include_archived: bool = False,
|
||||
allowed_project_ids: set[uuid.UUID] | None = None,
|
||||
date_from: datetime.datetime | None = None,
|
||||
date_to: datetime.datetime | None = None,
|
||||
) -> list[domain.Placement]:
|
||||
query = domain.Placement.filter(workspace_id=workspace_id)
|
||||
|
||||
@@ -402,6 +404,11 @@ class Postgres(DatabaseBase, Database):
|
||||
if creative_id:
|
||||
query = query.filter(creative_id=creative_id)
|
||||
|
||||
if date_from:
|
||||
query = query.filter(wanted_placement_date__gte=date_from)
|
||||
if date_to:
|
||||
query = query.filter(wanted_placement_date__lte=date_to)
|
||||
|
||||
if not include_archived:
|
||||
query = query.filter(status=domain.PlacementStatus.ACTIVE)
|
||||
|
||||
@@ -409,7 +416,7 @@ class Postgres(DatabaseBase, Database):
|
||||
await query.prefetch_related(
|
||||
'project', 'project__channel', 'placement_channel', 'creative', 'post', 'post__channel'
|
||||
)
|
||||
.order_by('-placement_date')
|
||||
.order_by('-wanted_placement_date')
|
||||
.all()
|
||||
)
|
||||
|
||||
@@ -432,6 +439,25 @@ class Postgres(DatabaseBase, Database):
|
||||
async def update_subscription(self, subscription: domain.Subscription) -> None:
|
||||
await subscription.save()
|
||||
|
||||
async def get_subscriptions_for_placements(
|
||||
self,
|
||||
placement_ids: list[uuid.UUID],
|
||||
*,
|
||||
date_from: datetime.datetime | None = None,
|
||||
date_to: datetime.datetime | None = None,
|
||||
) -> list[domain.Subscription]:
|
||||
if not placement_ids:
|
||||
return []
|
||||
|
||||
query = domain.Subscription.filter(placement_id__in=placement_ids)
|
||||
|
||||
if date_from:
|
||||
query = query.filter(created_at__gte=date_from)
|
||||
if date_to:
|
||||
query = query.filter(created_at__lte=date_to)
|
||||
|
||||
return await query.all()
|
||||
|
||||
async def get_active_subscriptions_by_subscriber_and_project(
|
||||
self, subscriber_id: uuid.UUID, project_id: uuid.UUID
|
||||
) -> list[domain.Subscription]:
|
||||
|
||||
Reference in New Issue
Block a user