26e5b9343d
Add PDF report generation for Metrologist dashboard with SPC and measurement reports including SVG charts, capability indices, and company logo embedding. New files: - server/services/report_service.py (Jinja2 + Plotly/Kaleido + WeasyPrint) - server/routers/reports.py (2 GET endpoints with auth) - server/templates/reports/ (base, spc, measurement HTML templates) Modified: - server/main.py (register reports router) - client dashboard (download buttons + proxy routes) - i18n strings IT/EN Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
"""TieMeasureFlow Server - FastAPI Entry Point."""
|
|
from contextlib import asynccontextmanager
|
|
from collections.abc import AsyncGenerator
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from config import settings
|
|
from database import init_db
|
|
from middleware.logging import AccessLogMiddleware
|
|
from routers.auth import router as auth_router
|
|
from routers.users import router as users_router
|
|
from routers.recipes import router as recipes_router
|
|
from routers.tasks import router as tasks_router
|
|
from routers.measurements import router as measurements_router
|
|
from routers.files import router as files_router
|
|
from routers.settings import router as settings_router
|
|
from routers.reports import router as reports_router
|
|
from routers.statistics import router as statistics_router
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|
"""Application lifespan: startup and shutdown events."""
|
|
# Startup
|
|
# Ensure upload directories exist
|
|
for subdir in ["images", "pdfs", "logos", "reports"]:
|
|
(settings.upload_path / subdir).mkdir(parents=True, exist_ok=True)
|
|
|
|
yield
|
|
|
|
# Shutdown (cleanup if needed)
|
|
|
|
|
|
app = FastAPI(
|
|
title="TieMeasureFlow API",
|
|
description="API per gestione task misurazioni con calibro manuale",
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# CORS middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
# Access logging middleware
|
|
app.add_middleware(AccessLogMiddleware)
|
|
|
|
# Register routers
|
|
app.include_router(auth_router)
|
|
app.include_router(users_router)
|
|
app.include_router(recipes_router)
|
|
app.include_router(tasks_router)
|
|
app.include_router(measurements_router)
|
|
app.include_router(files_router)
|
|
app.include_router(settings_router)
|
|
app.include_router(statistics_router)
|
|
app.include_router(reports_router)
|
|
|
|
|
|
@app.get("/api/health")
|
|
async def health_check() -> dict:
|
|
"""Health check endpoint."""
|
|
return {"status": "ok", "service": "TieMeasureFlow API", "version": "0.1.0"}
|