2025-05-17 02:28:21 +00:00

38 lines
901 B
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
class TodoBase(BaseModel):
"""
Base schema for Todo items
"""
title: str = Field(..., min_length=1, max_length=100)
description: Optional[str] = Field(None, max_length=500)
completed: bool = False
class TodoCreate(TodoBase):
"""
Schema for creating a new Todo item
"""
pass
class TodoUpdate(BaseModel):
"""
Schema for updating a Todo item
"""
title: Optional[str] = Field(None, min_length=1, max_length=100)
description: Optional[str] = Field(None, max_length=500)
completed: Optional[bool] = None
class TodoResponse(TodoBase):
"""
Schema for Todo response that includes database fields
"""
id: int
created_at: datetime
updated_at: Optional[datetime] = None
class Config:
from_attributes = True