From c219aaac1acd286a0c256ef486e6ca81305c080a Mon Sep 17 00:00:00 2001 From: JSC Date: Fri, 25 Jul 2025 11:24:03 +0200 Subject: [PATCH] Add API routing for v1 endpoints and health check functionality --- app/api/__init__.py | 11 +++++++++++ app/api/v1/__init__.py | 11 +++++++++++ app/api/v1/main.py | 16 ++++++++++++++++ app/main.py | 9 +++------ 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 app/api/__init__.py create mode 100644 app/api/v1/__init__.py create mode 100644 app/api/v1/main.py diff --git a/app/api/__init__.py b/app/api/__init__.py new file mode 100644 index 0000000..5a6019f --- /dev/null +++ b/app/api/__init__.py @@ -0,0 +1,11 @@ +"""API package.""" + +from fastapi import APIRouter + +from app.api import v1 + +# Main API router with /api prefix +api_router = APIRouter(prefix="/api") + +# Include version routers +api_router.include_router(v1.api_router) \ No newline at end of file diff --git a/app/api/v1/__init__.py b/app/api/v1/__init__.py new file mode 100644 index 0000000..f67827b --- /dev/null +++ b/app/api/v1/__init__.py @@ -0,0 +1,11 @@ +"""API v1 package.""" + +from fastapi import APIRouter + +from app.api.v1 import main + +# V1 API router with v1 prefix +api_router = APIRouter(prefix="/v1") + +# Include all route modules +api_router.include_router(main.router, tags=["main"]) diff --git a/app/api/v1/main.py b/app/api/v1/main.py new file mode 100644 index 0000000..3daae47 --- /dev/null +++ b/app/api/v1/main.py @@ -0,0 +1,16 @@ +"""Main router for v1 endpoints.""" + +from fastapi import APIRouter + +from app.core.logging import get_logger + +router = APIRouter() + +logger = get_logger(__name__) + + +@router.get("/") +def health() -> dict[str, str]: + """Health check endpoint.""" + logger.info("Health check endpoint accessed") + return {"status": "healthy"} \ No newline at end of file diff --git a/app/main.py b/app/main.py index c816fa1..627bbe4 100644 --- a/app/main.py +++ b/app/main.py @@ -3,6 +3,7 @@ from contextlib import asynccontextmanager from fastapi import FastAPI +from app.api import api_router from app.core.database import init_db from app.core.logging import get_logger, setup_logging from app.middleware.logging import LoggingMiddleware @@ -29,12 +30,8 @@ def create_app() -> FastAPI: app.add_middleware(LoggingMiddleware) - logger = get_logger(__name__) - - @app.get("/") - def health() -> dict[str, str]: - logger.info("Health check endpoint accessed") - return {"status": "healthy"} + # Include API routes + app.include_router(api_router) return app