(hero_id: int, hero: HeroUpdate)
| 82 | |
| 83 | @app.patch("/heroes/{hero_id}", response_model=HeroPublic) |
| 84 | def update_hero(hero_id: int, hero: HeroUpdate): |
| 85 | with Session(engine) as session: |
| 86 | db_hero = session.get(Hero, hero_id) |
| 87 | if not db_hero: |
| 88 | raise HTTPException(status_code=404, detail="Hero not found") |
| 89 | hero_data = hero.model_dump(exclude_unset=True) |
| 90 | extra_data = {} |
| 91 | if "password" in hero_data: |
| 92 | password = hero_data["password"] |
| 93 | hashed_password = hash_password(password) |
| 94 | extra_data["hashed_password"] = hashed_password |
| 95 | db_hero.sqlmodel_update(hero_data, update=extra_data) |
| 96 | session.add(db_hero) |
| 97 | session.commit() |
| 98 | session.refresh(db_hero) |
| 99 | return db_hero |
nothing calls this directly
no test coverage detected
searching dependent graphs…