59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
"""Pydantic response schemas for analytics endpoints."""
|
|
|
|
from datetime import date
|
|
from uuid import UUID
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from app.services.analytics_service import Age4Projection, WorkspaceOverview
|
|
|
|
|
|
class Age4ProjectionResponse(BaseModel):
|
|
personal_data_uuid: UUID
|
|
child_id: UUID
|
|
birth_date: date
|
|
fourth_birthday: date
|
|
total_days: int
|
|
days_used: int
|
|
planned_days_before_b4: int
|
|
projected_left_at_b4: int
|
|
savable_after_b4: int
|
|
expiring_at_b4: int
|
|
|
|
@classmethod
|
|
def from_entity(cls, p: Age4Projection) -> "Age4ProjectionResponse":
|
|
return cls(
|
|
personal_data_uuid=p.personal_data_uuid,
|
|
child_id=p.child_id,
|
|
birth_date=p.birth_date,
|
|
fourth_birthday=p.fourth_birthday,
|
|
total_days=p.total_days,
|
|
days_used=p.days_used,
|
|
planned_days_before_b4=p.planned_days_before_b4,
|
|
projected_left_at_b4=p.projected_left_at_b4,
|
|
savable_after_b4=p.savable_after_b4,
|
|
expiring_at_b4=p.expiring_at_b4,
|
|
)
|
|
|
|
|
|
class WorkspaceOverviewResponse(BaseModel):
|
|
workspace_id: UUID
|
|
child_id: UUID
|
|
parent_projections: list[Age4ProjectionResponse]
|
|
combined_days_used: int
|
|
combined_days_left: int
|
|
combined_expiring_at_b4: int
|
|
|
|
@classmethod
|
|
def from_entity(cls, overview: WorkspaceOverview) -> "WorkspaceOverviewResponse":
|
|
return cls(
|
|
workspace_id=overview.workspace_id,
|
|
child_id=overview.child_id,
|
|
parent_projections=[
|
|
Age4ProjectionResponse.from_entity(p) for p in overview.parent_projections
|
|
],
|
|
combined_days_used=overview.combined_days_used,
|
|
combined_days_left=overview.combined_days_left,
|
|
combined_expiring_at_b4=overview.combined_expiring_at_b4,
|
|
)
|