43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from contextlib import asynccontextmanager
|
|
from sqlalchemy import select
|
|
from app.database import init_db, async_session
|
|
from app.models.user import User
|
|
from app.routers import auth, documents
|
|
from app.utils.security import hash_password
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
await init_db()
|
|
# Seed admin user
|
|
async with async_session() as db:
|
|
result = await db.execute(select(User).where(User.email == "admin@clio.com"))
|
|
if not result.scalar_one_or_none():
|
|
admin = User(
|
|
email="admin@clio.com",
|
|
name="Admin CLIO",
|
|
password_hash=hash_password("Clio@2026"),
|
|
plan="premium"
|
|
)
|
|
db.add(admin)
|
|
await db.commit()
|
|
yield
|
|
|
|
app = FastAPI(title="CLIO API", version="1.0.0", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(auth.router)
|
|
app.include_router(documents.router)
|
|
|
|
@app.get("/api/health")
|
|
async def health():
|
|
return {"status": "ok", "app": "CLIO API v1.0 — Scanner Inteligente com IA"}
|