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
30 lines
614 B
Python
30 lines
614 B
Python
"""Shared response schemas and the standardized error envelope."""
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class ErrorDetail(BaseModel):
|
|
"""Standard error payload returned for all non-2xx responses.
|
|
|
|
``errors`` is only present for validation failures (HTTP 422) and
|
|
carries the per-field details.
|
|
"""
|
|
|
|
detail: str
|
|
code: str
|
|
errors: list[dict] | None = None
|
|
|
|
|
|
class HealthResponse(BaseModel):
|
|
"""Payload of the health check endpoints."""
|
|
|
|
status: str = "ok"
|
|
version: str
|
|
|
|
|
|
class VersionResponse(BaseModel):
|
|
"""Payload of the version endpoint."""
|
|
|
|
app: str
|
|
version: str
|