mirror of
https://github.com/fastapi/sqlmodel.git
synced 2025-08-15 02:07:54 +08:00
📝 Update ModelRead to ModelPublic documentation and examples (#885)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
@ -19,7 +19,7 @@ class HeroCreate(HeroBase):
|
||||
password: str
|
||||
|
||||
|
||||
class HeroRead(HeroBase):
|
||||
class HeroPublic(HeroBase):
|
||||
id: int
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ def on_startup():
|
||||
create_db_and_tables()
|
||||
|
||||
|
||||
@app.post("/heroes/", response_model=HeroRead)
|
||||
@app.post("/heroes/", response_model=HeroPublic)
|
||||
def create_hero(hero: HeroCreate):
|
||||
hashed_password = hash_password(hero.password)
|
||||
with Session(engine) as session:
|
||||
@ -66,14 +66,14 @@ def create_hero(hero: HeroCreate):
|
||||
return db_hero
|
||||
|
||||
|
||||
@app.get("/heroes/", response_model=list[HeroRead])
|
||||
@app.get("/heroes/", response_model=list[HeroPublic])
|
||||
def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)):
|
||||
with Session(engine) as session:
|
||||
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
|
||||
return heroes
|
||||
|
||||
|
||||
@app.get("/heroes/{hero_id}", response_model=HeroRead)
|
||||
@app.get("/heroes/{hero_id}", response_model=HeroPublic)
|
||||
def read_hero(hero_id: int):
|
||||
with Session(engine) as session:
|
||||
hero = session.get(Hero, hero_id)
|
||||
@ -82,7 +82,7 @@ def read_hero(hero_id: int):
|
||||
return hero
|
||||
|
||||
|
||||
@app.patch("/heroes/{hero_id}", response_model=HeroRead)
|
||||
@app.patch("/heroes/{hero_id}", response_model=HeroPublic)
|
||||
def update_hero(hero_id: int, hero: HeroUpdate):
|
||||
with Session(engine) as session:
|
||||
db_hero = session.get(Hero, hero_id)
|
||||
|
Reference in New Issue
Block a user