82 lines
2.2 KiB
Python
82 lines
2.2 KiB
Python
import os
|
|
import sys
|
|
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
|
|
if __package__ in {None, ""}:
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
import uvicorn
|
|
|
|
from app.api.auth import router as auth_router
|
|
from app.api.mixes import router as mixes_router
|
|
from app.api.powerbi import router as powerbi_router
|
|
from app.api.products import router as products_router
|
|
from app.api.raw_materials import router as raw_materials_router
|
|
from app.api.scenarios import router as scenarios_router
|
|
from app.core.config import settings
|
|
from app.db.session import Base, engine
|
|
from app.seed import seed_if_empty
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(_: FastAPI):
|
|
Base.metadata.create_all(bind=engine)
|
|
seed_if_empty()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title=settings.app_name, lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(auth_router)
|
|
app.include_router(raw_materials_router)
|
|
app.include_router(mixes_router)
|
|
app.include_router(products_router)
|
|
app.include_router(scenarios_router)
|
|
app.include_router(powerbi_router)
|
|
|
|
|
|
@app.get("/")
|
|
def root():
|
|
return {
|
|
"app": settings.app_name,
|
|
"message": "Use the operator frontend to sign in, manage raw materials, and review downstream mix and product costs.",
|
|
"workflow": [
|
|
"Sign in as an operator",
|
|
"Update raw material prices or add new materials",
|
|
"Review mix master recalculations",
|
|
"Confirm finished product pricing outputs",
|
|
],
|
|
"endpoints": {
|
|
"login": "/api/auth/login",
|
|
"raw_materials": "/api/raw-materials",
|
|
"mixes": "/api/mixes",
|
|
"products": "/api/products",
|
|
"scenarios": "/api/scenarios",
|
|
"docs": "/docs",
|
|
},
|
|
}
|
|
|
|
|
|
@app.get("/health")
|
|
def healthcheck():
|
|
return {"status": "ok"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(
|
|
app,
|
|
host=os.getenv("HOST", "0.0.0.0"),
|
|
port=int(os.getenv("PORT", "8000")),
|
|
)
|