juggl/backend/src/models/project.py

26 lines
1 KiB
Python
Raw Normal View History

2021-12-21 21:00:58 +01:00
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,
}