todoapp-ns86xt/main.py
Automated Action 29a0093f29 Implement CRUD API endpoints for todo management
- Add comprehensive todo endpoints in app/api/endpoints/todos.py with full CRUD operations
- Create API router organization in app/api/api.py
- Integrate API routes with main FastAPI app using /api/v1 prefix
- Include proper HTTP status codes, error handling, and REST conventions
- Add proper package initialization files for all modules
- Clean up temporary validation and migration files
- Update README with current project structure

API endpoints available:
- GET /api/v1/todos - list all todos
- POST /api/v1/todos - create new todo
- GET /api/v1/todos/{id} - get specific todo
- PUT /api/v1/todos/{id} - update todo
- DELETE /api/v1/todos/{id} - delete todo
2025-06-20 23:20:28 +00:00

61 lines
1.6 KiB
Python

from fastapi import FastAPI, Depends
from fastapi.middleware.cors import CORSMiddleware
from sqlalchemy.orm import Session
from app.db.session import get_db, engine
from app.db.base import Base
# Create database tables
Base.metadata.create_all(bind=engine)
# Initialize FastAPI app
app = FastAPI(
title="Todo App API",
description="A simple Todo application API built with FastAPI",
version="1.0.0",
docs_url="/docs",
redoc_url="/redoc",
openapi_url="/openapi.json"
)
# CORS configuration - allow all origins
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def root():
"""Base URL endpoint with app information and links"""
return {
"title": "Todo App API",
"description": "A simple Todo application API built with FastAPI",
"version": "1.0.0",
"documentation": {
"swagger_ui": "/docs",
"redoc": "/redoc",
"openapi_json": "/openapi.json"
},
"health_check": "/health"
}
@app.get("/health")
async def health_check(db: Session = Depends(get_db)):
"""Health check endpoint that reports application health"""
try:
# Test database connection
db.execute("SELECT 1")
db_status = "healthy"
except Exception as e:
db_status = f"unhealthy: {str(e)}"
return {
"status": "healthy" if db_status == "healthy" else "unhealthy",
"database": db_status,
"service": "Todo App API",
"version": "1.0.0"
}