57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
"""
|
|
Pydantic schemas for Todo
|
|
"""
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class TodoBase(BaseModel):
|
|
"""
|
|
Base Todo schema with shared attributes
|
|
"""
|
|
title: str = Field(..., min_length=1, max_length=255, description="The title of the todo item")
|
|
description: str | None = Field(None, description="Optional detailed description of the todo item")
|
|
completed: bool = Field(False, description="Whether the todo item is completed")
|
|
|
|
|
|
class TodoCreate(TodoBase):
|
|
"""
|
|
Schema for creating a new Todo
|
|
"""
|
|
pass
|
|
|
|
|
|
class TodoUpdate(BaseModel):
|
|
"""
|
|
Schema for updating an existing Todo
|
|
"""
|
|
title: str | None = Field(None, min_length=1, max_length=255, description="The title of the todo item")
|
|
description: str | None = Field(None, description="Optional detailed description of the todo item")
|
|
completed: bool | None = Field(None, description="Whether the todo item is completed")
|
|
|
|
|
|
class TodoInDB(TodoBase):
|
|
"""
|
|
Schema for Todo as stored in the database
|
|
"""
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
"""
|
|
Pydantic configuration
|
|
"""
|
|
from_attributes = True
|
|
json_encoders = {
|
|
datetime: lambda v: v.isoformat()
|
|
}
|
|
|
|
|
|
class Todo(TodoInDB):
|
|
"""
|
|
Schema for Todo response
|
|
"""
|
|
pass
|