2025-05-17 04:14:41 +00:00

33 lines
1.1 KiB
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
class TodoBase(BaseModel):
"""Base schema for Todo data."""
title: str = Field(..., min_length=1, max_length=100, description="Title of the todo item")
description: Optional[str] = Field(None, description="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: Optional[str] = Field(None, min_length=1, max_length=100, description="Title of the todo item")
description: Optional[str] = Field(None, description="Description of the todo item")
completed: Optional[bool] = Field(None, description="Whether the todo item is completed")
class TodoInDB(TodoBase):
"""Schema for Todo in the database."""
id: int
created_at: datetime
updated_at: datetime
class Config:
from_attributes = True
class Todo(TodoInDB):
"""Schema for Todo response."""
pass