
- Create User model and schema - Implement password hashing with bcrypt - Add JWT token-based authentication - Create user and auth endpoints - Update todo endpoints with user authentication - Add alembic migration for user model - Update README with new features
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api import auth_router, todos_router, users_router
|
|
from app.db.database import Base, engine
|
|
|
|
# Create tables in database
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title="Simple Todo Application with Authentication",
|
|
description="A todo application API built with FastAPI and user authentication",
|
|
version="0.2.0",
|
|
)
|
|
|
|
# Setup CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(auth_router)
|
|
app.include_router(users_router)
|
|
app.include_router(todos_router)
|
|
|
|
# Health endpoint
|
|
@app.get("/health", tags=["Health"])
|
|
def health_check():
|
|
"""
|
|
Health check endpoint to verify the API is running
|
|
"""
|
|
return {"status": "healthy"}
|
|
|
|
|
|
@app.get("/", tags=["Root"])
|
|
def read_root():
|
|
"""
|
|
Root endpoint with links to API documentation
|
|
"""
|
|
return {
|
|
"message": "Welcome to the Simple Todo Application API with User Authentication",
|
|
"documentation": "/docs",
|
|
"alternative_doc": "/redoc",
|
|
} |