|
@ -44,16 +44,16 @@ def get_session(): |
|
|
yield session |
|
|
yield session |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@asynccontextmanager |
|
|
@asynccontextmanager |
|
|
async def lifespan(app: FastAPI): |
|
|
async def lifespan(app: FastAPI): |
|
|
create_db_and_tables() # Startup |
|
|
create_db_and_tables() # Startup |
|
|
yield # Allows app to run |
|
|
yield # Allows app to run |
|
|
# Shutdown |
|
|
# Shutdown |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan) |
|
|
app = FastAPI(lifespan=lifespan) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/heroes/", response_model=HeroPublic) |
|
|
@app.post("/heroes/", response_model=HeroPublic) |
|
|
def create_hero(hero: HeroCreate, session: Session = Depends(get_session)): |
|
|
def create_hero(hero: HeroCreate, session: Session = Depends(get_session)): |
|
|
db_hero = Hero.model_validate(hero) |
|
|
db_hero = Hero.model_validate(hero) |
|
|