Files
erp-nutzfahrzeuge/backend/app/main.py
T
Leopoldadmin 2cf433a01c feat(T04): contact management + USt-IdNr. validation + contact UI
- Contact model: company, role (kaeufer/verkaeufer/beide), soft-delete
- ContactPerson model: 1:N relation with CASCADE delete
- USt-IdNr. validation: DE + 10 EU countries
- Contact CRUD: 7 API endpoints with RBAC, search/filter/paginate
- Frontend: ContactList, ContactForm, ContactDetail with EU/Inland toggle
- 73 backend tests (91% coverage), 20 frontend tests
2026-07-14 12:14:21 +02:00

60 lines
1.5 KiB
Python

"""FastAPI application entry point.
Configures CORS, registers routers under /api/v1, exposes health endpoint.
"""
from contextlib import asynccontextmanager
from fastapi import APIRouter, FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.config import settings
from app.routers import auth, contacts, users, vehicles
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Application startup and shutdown lifecycle."""
# Startup: could run alembic migrations here in production
yield
# Shutdown: cleanup resources
app = FastAPI(
title=settings.APP_NAME,
description="ERP Nutzfahrzeuge Backend API",
version="1.0.0",
lifespan=lifespan,
)
# CORS configuration from settings
app.add_middleware(
CORSMiddleware,
allow_origins=settings.cors_origins_list,
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
allow_headers=["*"],
)
# API v1 router
api_v1_router = APIRouter(prefix="/api/v1")
api_v1_router.include_router(auth.router)
api_v1_router.include_router(users.router)
api_v1_router.include_router(vehicles.router)
api_v1_router.include_router(contacts.router)
# Health endpoint (no auth required)
@api_v1_router.get("/health", tags=["health"])
async def health_check():
"""Health check endpoint."""
return {"status": "ok"}
app.include_router(api_v1_router)
@app.get("/")
async def root():
"""Root redirect info."""
return {"name": settings.APP_NAME, "version": "1.0.0", "docs": "/docs"}