c-stone-invoice-check/backend/main.py
Markus Kruse db8dc1dae3 feat(picker): Grabber (Direktlink-Download), Outbound-Queue, Accountable-Versand mit Freigabe
- Klassifikator: Direktlink nur Allowlist/https-PDF, Login-/Konsolen-Links -> portal
- grabber.py: INBOX/Archive/Trash readonly, Dedupe Message-ID + SHA-256
- Stichtag GRAB_CUTOFF: Rückblick = pending_review, neu = queued
- mailer.py: SMTP an ACCOUNTABLE_INBOX (ohne Adresse kein Versand)
- /outbound: Liste/xlsx, PDF-Vorschau, approve, run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 21:55:17 +01:00

84 lines
2.5 KiB
Python

"""
C-Stone Invoice Check — Hauptanwendung
FastAPI Backend für Email-Filterung und Rechnungsverarbeitung
"""
from fastapi import FastAPI, Depends, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from sqlalchemy.orm import Session
from sqlalchemy import text
from backend.database import get_db, engine, Base
# Models importieren für Alembic
from backend.models import Invoice, InvoiceDetail, Outbound, Base as ModelsBase
# Routers
from backend.routers import emails, invoices, auth, outbound
from backend.routers import settings as settings_router
# App erstellen
app = FastAPI(
title="C-Stone Invoice Check API",
description="Email-Filterung und Rechnungsverarbeitung",
version="1.0.0",
docs_url="/docs",
redoc_url="/redoc"
)
# CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Health Check
@app.get("/health")
async def health_check(db: Session = Depends(get_db)):
"""Health Check Endpoint"""
try:
db.execute(text("SELECT 1"))
return {"status": "healthy", "database": "connected"}
except Exception as e:
return {"status": "unhealthy", "database": "disconnected", "error": str(e)}
# Root Endpoint
@app.get("/")
async def root():
"""Root Endpoint"""
return {
"name": "C-Stone Invoice Check API",
"version": "1.0.0",
"status": "running",
"docs": "/docs"
}
# Initialisierung
@app.on_event("startup")
async def startup_event():
"""Datenbank erstellen bei Start"""
Base.metadata.create_all(bind=engine)
ModelsBase.metadata.create_all(bind=engine)
# create_all ergänzt keine Spalten an bestehenden Tabellen (kein alembic_version in Prod)
with engine.begin() as c:
c.execute(text("ALTER TABLE email_logs ADD COLUMN IF NOT EXISTS mail_class VARCHAR"))
c.execute(text("ALTER TABLE email_logs ADD COLUMN IF NOT EXISTS link_url TEXT"))
# Router einbinden
app.include_router(auth.router, prefix="/auth", tags=["authentication"])
app.include_router(emails.router, prefix="/emails", tags=["emails"])
app.include_router(invoices.router, prefix="/invoices", tags=["invoices"])
app.include_router(settings_router.router, prefix="/settings", tags=["settings"])
app.include_router(outbound.router, prefix="/outbound", tags=["invoice-picker"])
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8001)