Implement milestone M2 (backend setup):
- FastAPI app factory (core/app.py) with CORS, lifespan table
creation, and global error handlers using a standardized
{detail, code, errors?} envelope
- Endpoints: GET /health, GET /api/v1/health, GET /api/v1/version
- SQLAlchemy 2.0 ORM: Article, Author, Category models with
relationships, unique constraints, and FK pragma for SQLite
- Pydantic v2 schemas (create/update/read) for all models
- Env-driven config (DATABASE_URL, CORS_ORIGINS) + .env.example
- pytest suite (19 tests, ~95% coverage) with per-test SQLite
databases via fixtures
- Dockerfile (python:3.11-slim) and docker-compose.yml with a
persistent ./data/db volume and healthcheck
24 lines
727 B
Python
24 lines
727 B
Python
"""API v1 routes.
|
|
|
|
Mounted under ``/api/v1`` (see ``core.app.create_app``).
|
|
"""
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from config import APP_NAME, APP_VERSION
|
|
from schemas import HealthResponse, VersionResponse
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health", response_model=HealthResponse, summary="Service health check")
|
|
def get_health() -> HealthResponse:
|
|
"""Report service health (alternative path to the root ``/health``)."""
|
|
return HealthResponse(status="ok", version=APP_VERSION)
|
|
|
|
|
|
@router.get("/version", response_model=VersionResponse, summary="Application version")
|
|
def get_version() -> VersionResponse:
|
|
"""Return the application name and version."""
|
|
return VersionResponse(app=APP_NAME, version=APP_VERSION)
|