This commit is contained in:
2021-12-04 00:52:23 +03:00
commit c42316246f
19 changed files with 475 additions and 0 deletions

26
src/core/app.py Normal file
View File

@@ -0,0 +1,26 @@
from fastapi import FastAPI
from core.db import database
from app.views import router
def start_app() -> FastAPI:
app = FastAPI()
app.include_router(router)
app.state.database = database
@app.on_event('startup')
async def startup() -> None:
database_ = app.state.database
if not database_.is_connected:
await database_.connect()
@app.on_event('shutdown')
async def shutdown() -> None:
database_ = app.state.database
if database_.is_connected:
await database_.disconnect()
return app