51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""API schemas (Pydantic) for VacationDays.
|
|
|
|
Schemas are the API boundary — they validate request bodies and shape responses.
|
|
Keep them separate from domain entities so the wire format can evolve
|
|
independently. This is the REFERENCE for other entities' schemas.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from uuid import UUID
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from app.entities.vacation_days import VacationDays
|
|
|
|
|
|
class VacationDaysCreate(BaseModel):
|
|
personal_data_uuid: UUID
|
|
workspace_id: UUID
|
|
year: int = Field(ge=1900, le=2100)
|
|
total_days: int = Field(ge=0, le=366)
|
|
saved_days_in: int = Field(default=0, ge=0, le=366)
|
|
|
|
|
|
class VacationDaysUpdate(BaseModel):
|
|
total_days: int = Field(ge=0, le=366)
|
|
saved_days_in: int = Field(default=0, ge=0, le=366)
|
|
|
|
|
|
class VacationDaysResponse(BaseModel):
|
|
id: UUID
|
|
personal_data_uuid: UUID
|
|
workspace_id: UUID
|
|
year: int
|
|
total_days: int
|
|
saved_days_in: int
|
|
created_at: datetime | None
|
|
updated_at: datetime | None
|
|
|
|
@classmethod
|
|
def from_entity(cls, entity: VacationDays) -> "VacationDaysResponse":
|
|
return cls(
|
|
id=entity.id,
|
|
personal_data_uuid=entity.personal_data_uuid,
|
|
workspace_id=entity.workspace_id,
|
|
year=entity.year,
|
|
total_days=entity.total_days,
|
|
saved_days_in=entity.saved_days_in,
|
|
created_at=entity.created_at,
|
|
updated_at=entity.updated_at,
|
|
)
|