
- Created FastAPI application structure - Added Todo model and CRUD operations - Added database integration with SQLAlchemy - Added migrations with Alembic - Added health endpoint - Added API documentation with Swagger UI and ReDoc
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
|
|
class TodoBase(BaseModel):
|
|
"""Base Todo schema with common attributes"""
|
|
title: str = Field(..., min_length=1, max_length=100, description="Title of the todo")
|
|
description: Optional[str] = Field(None, max_length=500, description="Detailed description of the todo")
|
|
completed: bool = Field(False, description="Whether the todo is completed")
|
|
|
|
|
|
class TodoCreate(TodoBase):
|
|
"""Schema for creating a new todo"""
|
|
pass
|
|
|
|
|
|
class TodoUpdate(BaseModel):
|
|
"""Schema for updating an existing todo, all fields are optional"""
|
|
title: Optional[str] = Field(None, min_length=1, max_length=100, description="Title of the todo")
|
|
description: Optional[str] = Field(None, max_length=500, description="Detailed description of the todo")
|
|
completed: Optional[bool] = Field(None, description="Whether the todo is completed")
|
|
|
|
|
|
class TodoResponse(TodoBase):
|
|
"""Schema for todo response that includes database fields"""
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
"""ORM mode config for the TodoResponse schema"""
|
|
orm_mode = True
|
|
from_attributes = True |