Automated Action 53566813bd Complete Todo API implementation with FastAPI and SQLite
- Add SQLite database configuration
- Create Todo model, schemas, and CRUD operations
- Implement Todo API endpoints
- Add Alembic migration for todo table
- Set up database initialization in main.py
- Update README with project details and instructions
- Add pyproject.toml with Ruff configuration
2025-06-10 15:40:42 +00:00

79 lines
1.6 KiB
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
class TodoBase(BaseModel):
"""
Base schema for Todo items with common attributes.
"""
title: str = Field(
...,
min_length=1,
max_length=255,
description="The title of the todo item"
)
description: Optional[str] = Field(
None,
description="An optional detailed description of the todo item"
)
completed: bool = Field(
False,
description="Whether the todo item has been completed"
)
class TodoCreate(TodoBase):
"""
Schema for creating a new Todo item.
"""
pass
class TodoUpdate(BaseModel):
"""
Schema for updating an existing Todo item.
All fields are optional to allow partial updates.
"""
title: Optional[str] = Field(
None,
min_length=1,
max_length=255,
description="The title of the todo item"
)
description: Optional[str] = Field(
None,
description="An optional detailed description of the todo item"
)
completed: Optional[bool] = Field(
None,
description="Whether the todo item has been completed"
)
class TodoInDBBase(TodoBase):
"""
Schema for Todo items as stored in the database.
"""
id: int
created_at: datetime
updated_at: datetime
class Config:
from_attributes = True
class Todo(TodoInDBBase):
"""
Schema for Todo items returned to the client.
"""
pass
class TodoList(BaseModel):
"""
Schema for a list of Todo items.
"""
items: list[Todo]
count: int