refactor
This commit is contained in:
35
src/usecase/purchase/get_placement.py
Normal file
35
src/usecase/purchase/get_placement.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from src import domain, dto
|
||||
|
||||
from .create_placements import _build_placement_output
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .. import Usecase
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def get_placement_user(self: 'Usecase', input: dto.GetPlacementInput) -> dto.PlacementOutput:
|
||||
"""Get single placement by ID (user-managed)"""
|
||||
context = await self.ensure_workspace_permission(
|
||||
input.workspace_id, input.user_id, domain.PermissionKey.PLACEMENTS_READ
|
||||
)
|
||||
|
||||
project = await self.database.get_project(input.workspace_id, project_id=input.project_id)
|
||||
if not project:
|
||||
raise domain.ProjectNotFound(input.project_id)
|
||||
|
||||
context.ensure_project_permission(domain.PermissionKey.PLACEMENTS_READ, project.id)
|
||||
|
||||
placement = await self.database.get_placement(input.workspace_id, input.placement_id)
|
||||
if not placement or placement.project_id != project.id:
|
||||
raise domain.PlacementNotFound(input.placement_id)
|
||||
|
||||
# Prefetch channel for output building
|
||||
if placement.channel is None:
|
||||
channel = await self.database.get_channel(channel_id=placement.channel_id)
|
||||
placement.channel = channel
|
||||
|
||||
return _build_placement_output(placement)
|
||||
Reference in New Issue
Block a user