77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
import uuid
|
|
from typing import Annotated
|
|
|
|
from fastapi import Depends
|
|
from fastapi.routing import APIRouter
|
|
from fastapi_pagination import Page, paginate
|
|
|
|
from src import deps, dto
|
|
from src.adapter.jwt import JWTPayload
|
|
|
|
purchase_plan_channels_router = APIRouter(
|
|
prefix='/workspaces/{workspace_id}/projects/{project_id}/purchase-plan/channels',
|
|
tags=['purchase plan'],
|
|
)
|
|
|
|
|
|
@purchase_plan_channels_router.get('')
|
|
async def get_purchase_plan_channels(
|
|
workspace_id: uuid.UUID,
|
|
project_id: uuid.UUID,
|
|
current_user: Annotated[JWTPayload, Depends(deps.get_current_user)],
|
|
) -> Page[dto.PurchasePlanChannelOutput]:
|
|
input = dto.GetPurchasePlanChannelsInput(
|
|
user_id=current_user.user_id,
|
|
workspace_id=workspace_id,
|
|
project_id=project_id,
|
|
)
|
|
result = await deps.get_usecase().get_purchase_plan_channels(input=input)
|
|
return paginate(result) # type: ignore[no-any-return]
|
|
|
|
|
|
@purchase_plan_channels_router.post('')
|
|
async def attach_channel_to_purchase_plan(
|
|
request: dto.AttachChannelToPurchasePlanInput,
|
|
workspace_id: uuid.UUID,
|
|
project_id: uuid.UUID,
|
|
current_user: Annotated[JWTPayload, Depends(deps.get_current_user)],
|
|
) -> dto.PurchasePlanChannelOutput:
|
|
return await deps.get_usecase().attach_channel_to_purchase_plan(
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
user_id=current_user.user_id,
|
|
input=request,
|
|
)
|
|
|
|
|
|
@purchase_plan_channels_router.patch('/{channel_id}')
|
|
async def update_purchase_plan_channel(
|
|
channel_id: uuid.UUID,
|
|
request: dto.UpdatePurchasePlanChannelInput,
|
|
workspace_id: uuid.UUID,
|
|
project_id: uuid.UUID,
|
|
current_user: Annotated[JWTPayload, Depends(deps.get_current_user)],
|
|
) -> dto.PurchasePlanChannelOutput:
|
|
return await deps.get_usecase().update_purchase_plan_channel(
|
|
channel_id=channel_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
user_id=current_user.user_id,
|
|
input=request,
|
|
)
|
|
|
|
|
|
@purchase_plan_channels_router.delete('/{channel_id}')
|
|
async def remove_purchase_plan_channel(
|
|
channel_id: uuid.UUID,
|
|
workspace_id: uuid.UUID,
|
|
project_id: uuid.UUID,
|
|
current_user: Annotated[JWTPayload, Depends(deps.get_current_user)],
|
|
) -> None:
|
|
await deps.get_usecase().remove_purchase_plan_channel(
|
|
channel_id=channel_id,
|
|
project_id=project_id,
|
|
workspace_id=workspace_id,
|
|
user_id=current_user.user_id,
|
|
)
|