57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from modules.config_manager import ConfigManager
|
|
from modules.odoo_client import OdooClient
|
|
|
|
CONFIG_DIR = Path(__file__).parent / "config"
|
|
|
|
app_config = ConfigManager(
|
|
settings_path=str(CONFIG_DIR / "settings.yaml"),
|
|
services_path=str(CONFIG_DIR / "services.yaml"),
|
|
)
|
|
|
|
settings = app_config.get_settings()
|
|
odoo_settings = settings.get("odoo", {})
|
|
|
|
odoo_client = OdooClient(
|
|
url=odoo_settings.get("url", "http://localhost:8069"),
|
|
database=odoo_settings.get("database", "odoo"),
|
|
username=odoo_settings.get("username", "admin"),
|
|
password=odoo_settings.get("password", "admin"),
|
|
)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
try:
|
|
await odoo_client.authenticate()
|
|
except Exception as e:
|
|
print(f"Warning: Could not connect to Odoo: {e}")
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="TV Dashboard API", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
from routers import network, tasks, calendar, services
|
|
|
|
app.include_router(network.router)
|
|
app.include_router(tasks.router)
|
|
app.include_router(calendar.router)
|
|
app.include_router(services.router)
|
|
|
|
|
|
@app.get("/api/health")
|
|
async def health():
|
|
return {"status": "ok", "odoo_connected": odoo_client.uid is not None}
|