from datetime import datetime, timedelta from pydantic import BaseModel, Field from pydantic.json import timedelta_isoformat class ProjectNew(BaseModel): """Model used when a user creates a new project.""" name: str = Field(description="Name of the project", example="Learning") class ProjectInfo(BaseModel): """Model used when querying information about a module.""" name: str = Field(description="Name of the project", example="Learning") start_date: datetime = Field(description="Project creation date", example=datetime.now()) duration: timedelta = Field(description="Total tracked duration", example=timedelta(days=3, hours=5, minutes=47)) records: int = Field(description="Total number of trackings/records", example=42) class Config: # TODO: Adding this config may be done with a decorator """pydantic config""" json_encoders = { # Serialize timedeltas as ISO 8601 and not as float seconds, which is the default timedelta: timedelta_isoformat, }