@ -28,16 +28,16 @@ def get_session():
yield session
@asynccontextmanager
async def lifespan(app: FastAPI):
create_db_and_tables() # Startup
yield # Allows app to run
# Shutdown
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/")
def create_hero(hero: Hero, session: Session = Depends(get_session)) -> Hero:
session.add(hero)
@ -41,6 +41,7 @@ async def lifespan(app:FastAPI):
def create_hero(hero: Hero, session: SessionDep) -> Hero:
@ -30,6 +30,7 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)]
@ -37,8 +38,10 @@ async def lifespan(app:FastAPI):
# Statements below yield are ran after shutdown
@ -31,15 +31,16 @@ def get_session():
@ -27,15 +27,16 @@ def get_session():
@ -28,15 +28,16 @@ def get_session():
@ -45,8 +45,6 @@ def get_session():
create_db_and_tables() # StartUp
@ -56,6 +54,7 @@ async def lifespan(app:FastAPI):
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: Session = Depends(get_session)):
db_hero = Hero.model_validate(hero)
@ -55,8 +55,10 @@ async def lifespan(app:FastAPI):
def create_hero(hero: HeroCreate, session: SessionDep):
@ -54,8 +54,10 @@ async def lifespan(app:FastAPI):
@ -44,16 +44,16 @@ def get_session():
@ -45,15 +45,16 @@ def get_session():