домен обновлен
This commit is contained in:
@@ -291,11 +291,11 @@ class Postgres(DatabaseBase, Database):
|
||||
)
|
||||
|
||||
async def get_purchase(self, workspace_id: uuid.UUID, purchase_id: uuid.UUID) -> domain.Purchase | None:
|
||||
return await domain.Purchase.get_or_none(id=purchase_id, workspace_id=workspace_id)
|
||||
return await domain.Purchase.get_or_none(id=purchase_id, project__workspace_id=workspace_id)
|
||||
|
||||
async def get_project_purchases(self, workspace_id: uuid.UUID, project_id: uuid.UUID) -> list[domain.Purchase]:
|
||||
return (
|
||||
await domain.Purchase.filter(workspace_id=workspace_id, project_id=project_id)
|
||||
await domain.Purchase.filter(project__workspace_id=workspace_id, project_id=project_id)
|
||||
.prefetch_related('channels', 'channels__channel')
|
||||
.all()
|
||||
)
|
||||
@@ -315,6 +315,13 @@ class Postgres(DatabaseBase, Database):
|
||||
.first()
|
||||
)
|
||||
|
||||
async def get_purchase_channel_by_id(self, purchase_channel_id: uuid.UUID) -> domain.PurchaseChannel | None:
|
||||
return (
|
||||
await domain.PurchaseChannel.filter(id=purchase_channel_id)
|
||||
.prefetch_related('channel', 'purchase', 'purchase__project')
|
||||
.first()
|
||||
)
|
||||
|
||||
async def get_purchase_channels_by_project(self, project_id: uuid.UUID) -> list[domain.PurchaseChannel]:
|
||||
return (
|
||||
await domain.PurchaseChannel.filter(
|
||||
@@ -378,9 +385,9 @@ class Postgres(DatabaseBase, Database):
|
||||
await domain.PurchaseChannel.filter(purchase_id=purchase_id, channel_id=channel_id).delete()
|
||||
|
||||
async def get_creative(self, workspace_id: uuid.UUID, creative_id: uuid.UUID) -> domain.Creative | None:
|
||||
return await domain.Creative.get_or_none(id=creative_id, workspace_id=workspace_id).prefetch_related(
|
||||
'project', 'project__channel'
|
||||
)
|
||||
return await domain.Creative.get_or_none(
|
||||
id=creative_id, project__workspace_id=workspace_id
|
||||
).prefetch_related('project', 'project__channel')
|
||||
|
||||
async def update_creative(self, creative: domain.Creative) -> None:
|
||||
await creative.save()
|
||||
@@ -392,7 +399,7 @@ class Postgres(DatabaseBase, Database):
|
||||
include_archived: bool = False,
|
||||
allowed_project_ids: set[uuid.UUID] | None = None,
|
||||
) -> list[domain.Creative]:
|
||||
query = domain.Creative.filter(workspace_id=workspace_id)
|
||||
query = domain.Creative.filter(project__workspace_id=workspace_id)
|
||||
|
||||
if project_id:
|
||||
query = query.filter(project_id=project_id)
|
||||
@@ -410,8 +417,16 @@ class Postgres(DatabaseBase, Database):
|
||||
await domain.Creative.filter(id=creative_id).delete()
|
||||
|
||||
async def get_placement(self, workspace_id: uuid.UUID, placement_id: uuid.UUID) -> domain.Placement | None:
|
||||
return await domain.Placement.get_or_none(id=placement_id, workspace_id=workspace_id).prefetch_related(
|
||||
'project', 'project__channel', 'placement_channel', 'creative', 'post', 'post__channel'
|
||||
return await domain.Placement.get_or_none(
|
||||
id=placement_id, project__workspace_id=workspace_id
|
||||
).prefetch_related(
|
||||
'project',
|
||||
'project__channel',
|
||||
'purchase_channel',
|
||||
'purchase_channel__channel',
|
||||
'creative',
|
||||
'post',
|
||||
'post__channel',
|
||||
)
|
||||
|
||||
async def create_placement(self, placement: domain.Placement) -> None:
|
||||
@@ -431,7 +446,7 @@ class Postgres(DatabaseBase, Database):
|
||||
date_from: datetime.datetime | None = None,
|
||||
date_to: datetime.datetime | None = None,
|
||||
) -> list[domain.Placement]:
|
||||
query = domain.Placement.filter(workspace_id=workspace_id)
|
||||
query = domain.Placement.filter(project__workspace_id=workspace_id)
|
||||
|
||||
if project_id:
|
||||
query = query.filter(project_id=project_id)
|
||||
@@ -440,7 +455,7 @@ class Postgres(DatabaseBase, Database):
|
||||
return []
|
||||
query = query.filter(project_id__in=list(allowed_project_ids))
|
||||
if placement_channel_id:
|
||||
query = query.filter(placement_channel_id=placement_channel_id)
|
||||
query = query.filter(purchase_channel__channel_id=placement_channel_id)
|
||||
if creative_id:
|
||||
query = query.filter(creative_id=creative_id)
|
||||
|
||||
@@ -454,7 +469,7 @@ class Postgres(DatabaseBase, Database):
|
||||
|
||||
return (
|
||||
await query.prefetch_related(
|
||||
'project', 'project__channel', 'placement_channel', 'creative', 'post', 'post__channel'
|
||||
'project', 'project__channel', 'purchase_channel', 'purchase_channel__channel', 'creative', 'post', 'post__channel'
|
||||
)
|
||||
.order_by('-wanted_placement_date')
|
||||
.all()
|
||||
@@ -464,9 +479,9 @@ class Postgres(DatabaseBase, Database):
|
||||
await domain.Placement.filter(id=placement_id).delete()
|
||||
|
||||
async def get_placement_by_invite_link(self, invite_link: str) -> domain.Placement | None:
|
||||
return await domain.Placement.get_or_none(invite_link=invite_link).prefetch_related(
|
||||
'project', 'project__channel', 'placement_channel', 'creative'
|
||||
)
|
||||
return await domain.Placement.get_or_none(
|
||||
purchase_channel__invite_link=invite_link
|
||||
).prefetch_related('project', 'project__channel', 'purchase_channel', 'purchase_channel__channel', 'creative')
|
||||
|
||||
async def create_subscription(self, subscription: domain.Subscription) -> None:
|
||||
await subscription.save()
|
||||
|
||||
Reference in New Issue
Block a user