This commit is contained in:
Artem Tsyrulnikov
2026-01-15 22:02:16 +03:00
parent 6ec26c96e3
commit 049024ebe8
72 changed files with 2417 additions and 2054 deletions

View File

@@ -26,9 +26,9 @@ from .creative.delete_creative import delete_creative
from .creative.get_creative import get_creative
from .creative.get_creatives import get_creatives
from .creative.update_creative import update_creative
from .placement.fetch_placement_post_cycle import fetch_placement_post_cycle
from .placement.get_placement import get_placement
from .placement.get_placements import get_placements
from .placement.fetch_publication_post_cycle import fetch_publication_post_cycle
from .placement.get_publication import get_publication
from .placement.get_publications import get_publications
from .project.archive_project import archive_project
from .project.delete_project import delete_project
from .project.disconnect_project_by_tg_id import disconnect_project_by_tg_id
@@ -38,9 +38,9 @@ from .project.move_project_to_workspace import move_project_to_workspace
from .project.tg_add_project import tg_add_project
from .project.update_project_invite_link_type import update_project_invite_link_type
from .project.update_project_permissions import update_project_permissions
from .purchase.create_purchase import create_purchase
from .purchase.get_purchase import get_purchase
from .purchase.get_purchases import get_purchases
from .purchase.create_placements import create_placements
from .purchase.get_placement import get_placement_user
from .purchase.get_placements import get_placements
from .subscription.handle_subscription import handle_subscription
from .subscription.handle_unsubscription import handle_unsubscription
from .views.get_views_history import get_views_history
@@ -171,43 +171,18 @@ class Database(typing.Protocol):
async def check_channel_exists_in_workspace(self, channel_id: UUID, workspace_id: UUID) -> bool: ...
async def get_active_purchase(self, project_id: UUID, creative_id: UUID) -> domain.Purchase | None: ...
# Placement methods (user-managed, бывший PurchaseChannel)
async def create_placement(self, placement: domain.Placement) -> None: ...
async def get_purchase(self, workspace_id: UUID, purchase_id: UUID) -> domain.Purchase | None: ...
async def create_placements(self, placements: list[domain.Placement]) -> None: ...
async def get_project_purchases(self, workspace_id: UUID, project_id: UUID) -> list[domain.Purchase]: ...
async def get_placement(self, workspace_id: UUID, placement_id: UUID) -> domain.Placement | None: ...
async def create_purchase(self, purchase: domain.Purchase) -> None: ...
async def get_project_placements(
self, workspace_id: UUID, project_id: UUID, include_archived: bool = False
) -> list[domain.Placement]: ...
async def get_purchase_channels(self, purchase_id: UUID) -> list[domain.PurchaseChannel]: ...
async def get_purchase_channel(
self, purchase_channel_id: UUID, purchase_id: UUID
) -> domain.PurchaseChannel | None: ...
async def get_purchase_channel_by_id(self, purchase_channel_id: UUID) -> domain.PurchaseChannel | None: ...
async def get_purchase_channels_by_project(self, project_id: UUID) -> list[domain.PurchaseChannel]: ...
async def add_channel_to_purchase(
self,
purchase_id: UUID,
channel_id: UUID,
invite_link: str,
invite_link_type: domain.purchase.InviteLinkType,
*,
status: domain.PurchaseChannelStatus | None = None,
comment: str | None = None,
placement_at: datetime.datetime | None = None,
cost_type: domain.purchase.CostType | None = None,
cost_value: float | None = None,
cost_before_bargain: float | None = None,
format: str | None = None,
) -> domain.PurchaseChannel: ...
async def update_purchase_channel(self, purchase_channel: domain.PurchaseChannel) -> None: ...
async def remove_channel_from_purchase(self, purchase_id: UUID, channel_id: UUID) -> None: ...
async def update_placement_user(self, placement: domain.Placement) -> None: ...
async def get_creative(self, workspace_id: UUID, creative_id: UUID) -> domain.Creative | None: ...
@@ -223,9 +198,10 @@ class Database(typing.Protocol):
async def delete_creative(self, creative_id: UUID) -> None: ...
async def get_placement(self, workspace_id: UUID, placement_id: UUID) -> domain.Placement | None: ...
# Publication methods (system-managed, бывший Placement)
async def get_publication(self, workspace_id: UUID, publication_id: UUID) -> domain.Publication | None: ...
async def get_workspace_placements(
async def get_workspace_publications(
self,
workspace_id: UUID,
project_id: UUID | None = None,
@@ -235,27 +211,28 @@ class Database(typing.Protocol):
allowed_project_ids: set[UUID] | None = None,
date_from: datetime.datetime | None = None,
date_to: datetime.datetime | None = None,
) -> list[domain.Placement]: ...
) -> list[domain.Publication]: ...
async def create_placement(self, placement: domain.Placement) -> None: ...
async def create_publication(self, publication: domain.Publication) -> None: ...
async def update_placement(self, placement: domain.Placement) -> None: ...
async def update_publication(self, publication: domain.Publication) -> None: ...
async def delete_placement(self, placement_id: UUID) -> None: ...
async def delete_publication(self, publication_id: UUID) -> None: ...
async def get_placement_by_invite_link(self, invite_link: str) -> domain.Placement | None: ...
async def get_publication_by_invite_link(self, invite_link: str) -> domain.Publication | None: ...
# Subscription methods
async def create_subscription(self, subscription: domain.Subscription) -> None: ...
async def get_subscription_by_subscriber_and_placement(
self, telegram_user_id: UUID, placement_id: UUID
async def get_subscription_by_subscriber_and_publication(
self, telegram_user_id: UUID, publication_id: UUID
) -> domain.Subscription | None: ...
async def update_subscription(self, subscription: domain.Subscription) -> None: ...
async def get_subscriptions_for_placements(
async def get_subscriptions_for_publications(
self,
placement_ids: list[UUID],
publication_ids: list[UUID],
*,
date_from: datetime.datetime | None = None,
date_to: datetime.datetime | None = None,
@@ -270,15 +247,17 @@ class Database(typing.Protocol):
) -> domain.Subscription | None: ...
# Count methods
async def count_placements_by_creative(self, creative_id: UUID) -> int: ...
async def count_publications_by_creative(self, creative_id: UUID) -> int: ...
async def count_subscriptions_by_placement(self, placement_id: UUID) -> int: ...
async def count_subscriptions_by_publication(self, publication_id: UUID) -> int: ...
async def count_placements_by_creative_batch(self, creative_ids: list[UUID]) -> dict[UUID, int]: ...
async def count_publications_by_creative_batch(self, creative_ids: list[UUID]) -> dict[UUID, int]: ...
async def count_subscriptions_by_placement_batch(self, placement_ids: list[UUID]) -> dict[UUID, int]: ...
async def count_subscriptions_by_publication_batch(
self, publication_ids: list[UUID]
) -> dict[UUID, int]: ...
async def has_placements_for_creative(self, creative_id: UUID) -> bool: ...
async def has_publications_for_creative(self, creative_id: UUID) -> bool: ...
# Post methods
async def create_post(self, post: domain.Post) -> None: ...
@@ -409,15 +388,6 @@ class Usecase:
return workspace
async def ensure_active_purchase(self, project: domain.Project, creative: domain.Creative) -> domain.Purchase:
purchase = await self.database.get_active_purchase(project.id, creative.id)
if purchase:
return purchase
purchase = domain.Purchase(project_id=project.id, creative_id=creative.id)
await self.database.create_purchase(purchase)
return purchase
validate_login_token = validate_login_token
create_telegram_login_token = create_telegram_login_token
get_jwt_by_telegram_id = get_jwt_by_telegram_id
@@ -434,17 +404,20 @@ class Usecase:
get_channels = get_channels
get_channel = get_channel
attach_channel_to_workspace = attach_channel_to_workspace
create_purchase = create_purchase
get_purchases = get_purchases
get_purchase = get_purchase
# Placement (user-managed) use cases
create_placements = create_placements
get_placements = get_placements
get_placement_user = get_placement_user
# Creative use cases
get_creatives = get_creatives
get_creative = get_creative
create_creative = create_creative
update_creative = update_creative
delete_creative = delete_creative
get_placements = get_placements
get_placement = get_placement
fetch_placement_post_cycle = fetch_placement_post_cycle
# Publication (system-managed) use cases
get_publications = get_publications
get_publication = get_publication
fetch_publication_post_cycle = fetch_publication_post_cycle
handle_subscription = handle_subscription
handle_unsubscription = handle_unsubscription
get_views_history = get_views_history