diff --git a/README.md b/README.md index 353ef88..fac5bf4 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ A RESTful API for managing tasks built with FastAPI and SQLite. - Task pagination - Automatic API documentation - Health check endpoint +- Root endpoint with API information +- Task status and priority validation using Enums ## Project Structure @@ -90,6 +92,10 @@ FastAPI generates interactive API documentation: ## API Endpoints +### Root Endpoint + +- `GET /` - Returns information about the API including the title, documentation links, and health check endpoint + ### Health Check - `GET /health` - Check if the API is running @@ -108,8 +114,8 @@ FastAPI generates interactive API documentation: { "title": "string", "description": "string", - "status": "string", - "priority": "string", + "status": "string", // One of: "pending", "in_progress", "completed", "cancelled" + "priority": "string", // One of: "low", "medium", "high", "urgent" "due_date": "datetime", "completed": false } diff --git a/app/database/base.py b/app/database/base.py index 609c9d8..55fa743 100644 --- a/app/database/base.py +++ b/app/database/base.py @@ -1 +1,5 @@ # Import all the models to ensure they are registered with SQLAlchemy +from app.database.base_class import Base # noqa +from app.models.task import Task # noqa + +# Add new models here as they are created diff --git a/app/schemas/task.py b/app/schemas/task.py index 5e98b1c..a21fb4d 100644 --- a/app/schemas/task.py +++ b/app/schemas/task.py @@ -1,14 +1,31 @@ from datetime import datetime +from enum import Enum from typing import Optional from pydantic import BaseModel +class TaskStatus(str, Enum): + """Valid status values for tasks.""" + PENDING = "pending" + IN_PROGRESS = "in_progress" + COMPLETED = "completed" + CANCELLED = "cancelled" + + +class TaskPriority(str, Enum): + """Valid priority values for tasks.""" + LOW = "low" + MEDIUM = "medium" + HIGH = "high" + URGENT = "urgent" + + class TaskBase(BaseModel): """Base Task schema with shared attributes.""" title: str description: Optional[str] = None - status: Optional[str] = "pending" - priority: Optional[str] = "medium" + status: TaskStatus = TaskStatus.PENDING + priority: TaskPriority = TaskPriority.MEDIUM due_date: Optional[datetime] = None completed: Optional[bool] = False @@ -22,8 +39,8 @@ class TaskUpdate(BaseModel): """Schema for updating an existing task.""" title: Optional[str] = None description: Optional[str] = None - status: Optional[str] = None - priority: Optional[str] = None + status: Optional[TaskStatus] = None + priority: Optional[TaskPriority] = None due_date: Optional[datetime] = None completed: Optional[bool] = None diff --git a/main.py b/main.py index 01d3b49..cbd476b 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import uvicorn from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware +from fastapi.responses import JSONResponse from app.api.v1.router import api_router from app.core.config import settings @@ -22,8 +23,21 @@ app.add_middleware( app.include_router(api_router) +@app.get("/", tags=["root"]) +async def root(): + """Root endpoint returning information about the API.""" + return JSONResponse( + content={ + "title": settings.PROJECT_NAME, + "documentation": "/docs", + "health_check": "/health" + } + ) + + @app.get("/health", tags=["health"]) async def health(): + """Health check endpoint.""" return {"status": "ok"}