|
@ -1,3 +1,4 @@ |
|
|
|
|
|
from contextlib import asynccontextmanager |
|
|
from typing import Annotated, Union |
|
|
from typing import Annotated, Union |
|
|
|
|
|
|
|
|
from fastapi import Depends, FastAPI, HTTPException, Query |
|
|
from fastapi import Depends, FastAPI, HTTPException, Query |
|
@ -45,13 +46,15 @@ def get_session(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SessionDep = Annotated[Session, Depends(get_session)] |
|
|
SessionDep = Annotated[Session, Depends(get_session)] |
|
|
app = FastAPI() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.on_event("startup") |
|
|
@asynccontextmanager |
|
|
def on_startup(): |
|
|
async def lifespan(app:FastAPI): |
|
|
create_db_and_tables() |
|
|
create_db_and_tables() #Startup |
|
|
|
|
|
yield #Allows app to run |
|
|
|
|
|
#Shutdown |
|
|
|
|
|
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan) |
|
|
|
|
|
|
|
|
@app.post("/heroes/", response_model=HeroPublic) |
|
|
@app.post("/heroes/", response_model=HeroPublic) |
|
|
def create_hero(hero: HeroCreate, session: SessionDep): |
|
|
def create_hero(hero: HeroCreate, session: SessionDep): |
|
|