refactor
This commit is contained in:
@@ -418,6 +418,7 @@ class Postgres(DatabaseBase):
|
||||
project_id: uuid.UUID | None = None,
|
||||
placement_channel_id: uuid.UUID | None = None,
|
||||
creative_id: uuid.UUID | None = None,
|
||||
placement_id: uuid.UUID | None = None,
|
||||
include_archived: bool = False,
|
||||
allowed_project_ids: set[uuid.UUID] | None = None,
|
||||
date_from: datetime.datetime | None = None,
|
||||
@@ -435,6 +436,8 @@ class Postgres(DatabaseBase):
|
||||
query = query.filter(placement__channel_id=placement_channel_id)
|
||||
if creative_id:
|
||||
query = query.filter(placement__creative_id=creative_id)
|
||||
if placement_id:
|
||||
query = query.filter(placement_id=placement_id)
|
||||
|
||||
if date_from:
|
||||
query = query.filter(created_at__gte=date_from)
|
||||
|
||||
@@ -18,6 +18,7 @@ async def list_placement_posts(
|
||||
project_id: uuid.UUID | None = None,
|
||||
placement_channel_id: uuid.UUID | None = None,
|
||||
creative_id: uuid.UUID | None = None,
|
||||
placement_id: uuid.UUID | None = None,
|
||||
include_archived: bool = False,
|
||||
) -> dto.GetPlacementPostsOutput:
|
||||
"""List all placement_posts (system-managed actual posts) in workspace"""
|
||||
@@ -27,6 +28,7 @@ async def list_placement_posts(
|
||||
project_id=project_id,
|
||||
placement_channel_id=placement_channel_id,
|
||||
creative_id=creative_id,
|
||||
placement_id=placement_id,
|
||||
include_archived=include_archived,
|
||||
)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import uuid
|
||||
import pydantic
|
||||
|
||||
from src import domain
|
||||
from src.dto.purchase import PlacementOutput
|
||||
|
||||
|
||||
class PlacementPostOutput(pydantic.BaseModel):
|
||||
@@ -23,6 +24,7 @@ class PlacementPostOutput(pydantic.BaseModel):
|
||||
status: domain.PlacementPostStatus
|
||||
subscriptions_count: int
|
||||
placement_id: uuid.UUID # Ссылка на Placement
|
||||
placement: PlacementOutput
|
||||
created_at: datetime.datetime
|
||||
|
||||
|
||||
@@ -32,6 +34,7 @@ class GetPlacementPostsInput(pydantic.BaseModel):
|
||||
project_id: uuid.UUID | None = None
|
||||
placement_channel_id: uuid.UUID | None = None
|
||||
creative_id: uuid.UUID | None = None
|
||||
placement_id: uuid.UUID | None = None
|
||||
include_archived: bool = False
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,13 @@ async def fetch_placement_post_cycle(self: 'Usecase', interval_seconds: int) ->
|
||||
|
||||
# Получаем все approved Placements с invite_link
|
||||
placements = (
|
||||
await domain.Placement.filter(status__in=[domain.PlacementStatus.APPROVED, domain.PlacementStatus.IN_PROGRESS])
|
||||
await domain.Placement.filter(
|
||||
status__in=[
|
||||
domain.PlacementStatus.APPROVED,
|
||||
domain.PlacementStatus.PLANNED,
|
||||
domain.PlacementStatus.IN_PROGRESS,
|
||||
]
|
||||
)
|
||||
.prefetch_related('channel', 'project')
|
||||
.all()
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from src import domain, dto
|
||||
from src.usecase.purchase.create_placements import _build_placement_output
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .. import Usecase
|
||||
@@ -51,5 +52,6 @@ async def get_placement_post(self: 'Usecase', input: dto.GetPlacementPostInput)
|
||||
status=placement_post.status,
|
||||
subscriptions_count=subscriptions_count,
|
||||
placement_id=placement.id,
|
||||
placement=_build_placement_output(placement),
|
||||
created_at=placement_post.created_at,
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from src import domain, dto
|
||||
from src.usecase.purchase.create_placements import _build_placement_output
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .. import Usecase
|
||||
@@ -26,6 +27,7 @@ async def get_placement_posts(self: 'Usecase', input: dto.GetPlacementPostsInput
|
||||
project_id=input.project_id,
|
||||
placement_channel_id=input.placement_channel_id,
|
||||
creative_id=input.creative_id,
|
||||
placement_id=input.placement_id,
|
||||
include_archived=input.include_archived,
|
||||
allowed_project_ids=allowed_project_ids,
|
||||
)
|
||||
@@ -64,6 +66,7 @@ async def get_placement_posts(self: 'Usecase', input: dto.GetPlacementPostsInput
|
||||
status=placement_post.status,
|
||||
subscriptions_count=subscriptions_counts.get(placement_post.id, 0),
|
||||
placement_id=placement.id,
|
||||
placement=_build_placement_output(placement),
|
||||
created_at=placement_post.created_at,
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user