
- Create app/db/base.py with SQLAlchemy Base definition - Create app/db/session.py with database engine and session setup using absolute path /app/storage/db/db.sqlite - Create app/models/todo.py with Todo model including id, title, description, completed, created_at, updated_at fields - Create app/schemas/todo.py with Pydantic schemas for TodoCreate, TodoUpdate, and TodoResponse - Add necessary __init__.py files for proper package structure
43 lines
1009 B
Python
43 lines
1009 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
app = FastAPI(
|
|
title="Todo App API",
|
|
description="A simple Todo application API built with FastAPI",
|
|
version="1.0.0",
|
|
openapi_url="/openapi.json",
|
|
docs_url="/docs",
|
|
redoc_url="/redoc"
|
|
)
|
|
|
|
# Configure CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
"""Base endpoint that returns app information"""
|
|
return {
|
|
"title": "Todo App API",
|
|
"description": "A simple Todo application API built with FastAPI",
|
|
"version": "1.0.0",
|
|
"documentation": "/docs",
|
|
"health_check": "/health"
|
|
}
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
"""Health check endpoint"""
|
|
return {"status": "healthy", "message": "Todo App API is running"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="0.0.0.0", port=8000) |