47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
from contextlib import asynccontextmanager
|
|
|
|
from dotenv import load_dotenv
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from scheduler.api import company_routes, employee_routes, health_routes, schedule_routes
|
|
from scheduler.database import Database
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
Database().initialize_schema()
|
|
yield
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
load_dotenv()
|
|
|
|
app = FastAPI(
|
|
title="manager_employees_python",
|
|
lifespan=lifespan,
|
|
openapi_url="/api-docs/openapi.json",
|
|
docs_url="/swagger-ui/",
|
|
)
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(health_routes.router)
|
|
app.include_router(company_routes.router)
|
|
app.include_router(employee_routes.router)
|
|
app.include_router(schedule_routes.router)
|
|
|
|
@app.get("/api-docs/openai.json", include_in_schema=False)
|
|
def openai_json_alias():
|
|
return app.openapi()
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|