74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
import datetime
|
|
import uuid
|
|
from typing import Annotated
|
|
|
|
from fastapi import Depends
|
|
from fastapi.routing import APIRouter
|
|
|
|
from src import deps, dto
|
|
from src.adapter.jwt import JWTPayload
|
|
|
|
analytics_router = APIRouter(prefix='/workspaces/{workspace_id}/analytics', tags=['analytics'])
|
|
|
|
|
|
@analytics_router.get('/placements')
|
|
async def get_placements_analytics(
|
|
workspace_id: uuid.UUID,
|
|
current_user: Annotated[JWTPayload, Depends(deps.get_current_user)],
|
|
project_id: uuid.UUID | None = None,
|
|
) -> dto.GetPlacementsAnalyticsOutput:
|
|
input = dto.GetPlacementsAnalyticsInput(
|
|
user_id=current_user.user_id,
|
|
workspace_id=workspace_id,
|
|
project_id=project_id,
|
|
)
|
|
return await deps.get_usecase().get_placements_analytics(input)
|
|
|
|
|
|
@analytics_router.get('/creatives')
|
|
async def get_creatives_analytics(
|
|
workspace_id: uuid.UUID,
|
|
current_user: Annotated[JWTPayload, Depends(deps.get_current_user)],
|
|
project_id: uuid.UUID | None = None,
|
|
) -> dto.GetCreativesAnalyticsOutput:
|
|
input = dto.GetCreativesAnalyticsInput(
|
|
user_id=current_user.user_id,
|
|
workspace_id=workspace_id,
|
|
project_id=project_id,
|
|
)
|
|
return await deps.get_usecase().get_creatives_analytics(input)
|
|
|
|
|
|
@analytics_router.get('/channels')
|
|
async def get_channel_analytics(
|
|
workspace_id: uuid.UUID,
|
|
current_user: Annotated[JWTPayload, Depends(deps.get_current_user)],
|
|
project_id: uuid.UUID | None = None,
|
|
) -> dto.GetChannelAnalyticsOutput:
|
|
input = dto.GetChannelAnalyticsInput(
|
|
user_id=current_user.user_id,
|
|
workspace_id=workspace_id,
|
|
project_id=project_id,
|
|
)
|
|
return await deps.get_usecase().get_channel_analytics(input)
|
|
|
|
|
|
@analytics_router.get('/spending')
|
|
async def get_spending_analytics(
|
|
workspace_id: uuid.UUID,
|
|
current_user: Annotated[JWTPayload, Depends(deps.get_current_user)],
|
|
project_id: uuid.UUID | None = None,
|
|
date_from: datetime.datetime | None = None,
|
|
date_to: datetime.datetime | None = None,
|
|
grouping: dto.DateGrouping = dto.DateGrouping.DAY,
|
|
) -> dto.GetSpendingAnalyticsOutput:
|
|
input = dto.GetSpendingAnalyticsInput(
|
|
user_id=current_user.user_id,
|
|
workspace_id=workspace_id,
|
|
project_id=project_id,
|
|
date_from=date_from,
|
|
date_to=date_to,
|
|
grouping=grouping,
|
|
)
|
|
return await deps.get_usecase().get_spending_analytics(input)
|