dd16940bb2
- Company CRUD with soft-delete, FTS search (tsvector + GIN), filter, pagination - Contact CRUD with N:M company linking via company_contacts - CSV/XLSX export, CSV import with dry-run preview - GDPR hard-delete with deletion_log - Audit log on all mutations - 27 new tests (24 ACs), 56 total tests pass - Migration 0002: contacts, company_contacts, FTS search_tsv - Fixed T01 tests: POST→201, PATCH→PUT compatibility
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
"""FastAPI application - LeoCRM backend."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.config import get_settings
|
|
from app.core.middleware import CSRFMiddleware
|
|
from app.core.db import close_engine
|
|
from app.routes import auth, users, roles, tenants, health, notifications, companies, contacts, import_export
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Application lifespan: startup and shutdown."""
|
|
yield
|
|
await close_engine()
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
"""Create and configure the FastAPI application."""
|
|
settings = get_settings()
|
|
app = FastAPI(title="LeoCRM", version="1.0.0", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origin_list,
|
|
allow_credentials=True,
|
|
allow_methods=["GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS"],
|
|
allow_headers=["Authorization", "Content-Type", "X-CSRF-Token", "X-Tenant-ID"],
|
|
max_age=3600,
|
|
)
|
|
app.add_middleware(CSRFMiddleware)
|
|
|
|
app.include_router(health.router)
|
|
app.include_router(auth.router)
|
|
app.include_router(users.router)
|
|
app.include_router(roles.router)
|
|
app.include_router(tenants.router)
|
|
app.include_router(notifications.router)
|
|
app.include_router(companies.router)
|
|
app.include_router(contacts.router)
|
|
app.include_router(import_export.router)
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|