-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (50 loc) · 1.67 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import asyncio
from contextlib import asynccontextmanager
from fastapi import FastAPI
from pydantic import BaseModel
from config import APP, DEBUG, DESCRIPTION, VERSION
from routes.api import router as api_router
from migrations.indexes import create_indexes
from migrations.migrations import run_migrations
tags_info = [
{"name": "Version", "description": "Version information"},
{"name": "Auth", "description": "Authentication related operations"},
{"name": "Admin", "description": "Operations for administrators"},
{"name": "Users", "description": "Users related operations"},
{
"name": "Admin: Users",
"description": "Users related operations for administrators",
},
{"name": "Companies", "description": "Companies related operations"},
{
"name": "Admin: Companies",
"description": "Companies related operations for administrators",
},
{"name": "Departments", "description": "Departments related operations"},
{
"name": "Admin: Departments",
"description": "Departments related operations for administrators",
},
]
@asynccontextmanager
async def lifespan(app: FastAPI):
await asyncio.gather(create_indexes(), run_migrations())
yield
# Application shutdown
app = FastAPI(
version=VERSION,
title=APP,
description=DESCRIPTION,
debug=DEBUG,
lifespan=lifespan,
openapi_tags=tags_info,
)
app.include_router(api_router)
class VersionInfo(BaseModel):
version: str
@app.get("/", response_model=VersionInfo, tags=["Version"])
def version():
return {"version": VERSION}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="localhost", port=8000)