Files
POPS/app/main.py
Martin Hohenberg 1259a7294a Remove internal filament management, integrate FilamentDB, add job detail page
Filament removal:
- Deleted app/models/filament.py, routers/filaments.py, templates/filaments.html
- Migration 0009: drops filaments table and filament_id FK from print_jobs
- Removed Filaments from sidebar and all internal references

FilamentDB integration (read-only):
- app/filamentdb.py: GET /reports/stock with 5-min in-memory cache
- available_materials() / available_colors() populate job form dropdowns
- Falls back to static constants if FilamentDB unreachable
- Dashboard filament count now from FilamentDB rolls_in_stock
- FILAMENTDB_URL added to .env.install; httpx added to requirements

Job detail page (/jobs/{id}):
- Two cards: Job info (customer, material, printer, bracket, timing, cost)
  and File & Geometry (bounding box + volume from stl_cache)
- Log timeline with Add Entry modal
- Filename in jobs list links to detail page

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 22:12:47 +02:00

60 lines
1.6 KiB
Python

import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from app.db import check_db, run_migrations
from app.routers import pricing, print_jobs, printer_types, printers, todos
from app.routers import ui
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)-8s %(name)s: %(message)s",
)
logger = logging.getLogger("pops")
@asynccontextmanager
async def lifespan(app: FastAPI):
ok, msg = check_db()
if ok:
logger.info("Database connection OK")
try:
run_migrations()
except Exception:
logger.exception("Migration failed — schema may be out of date")
else:
logger.warning("Database unreachable: %s", msg)
yield
app = FastAPI(title="POPS", lifespan=lifespan)
@app.exception_handler(Exception)
async def unhandled_exception(request: Request, exc: Exception):
logger.exception("Unhandled error on %s %s", request.method, request.url)
return JSONResponse(status_code=500, content={"detail": str(exc)})
# JSON API
app.include_router(printer_types.router, prefix="/api")
app.include_router(printers.router, prefix="/api")
app.include_router(print_jobs.router, prefix="/api")
app.include_router(todos.router, prefix="/api")
app.include_router(pricing.router, prefix="/api")
# Web UI
app.include_router(ui.router)
@app.get("/health")
def health():
ok, msg = check_db()
return {
"status": "ok" if ok else "degraded",
"db": "connected" if ok else "unreachable",
"detail": msg,
}