mirror of https://github.com/tiangolo/fastapi.git
Merge e0391ac7b5 into 272204c0c7
This commit is contained in:
commit
cdbd9608bb
|
|
@ -14,7 +14,7 @@ app = FastAPI()
|
||||||
|
|
||||||
@app.post("/items/")
|
@app.post("/items/")
|
||||||
async def create_item(item: Item):
|
async def create_item(item: Item):
|
||||||
item_dict = item.dict()
|
item_dict = item.model_dump()
|
||||||
if item.tax is not None:
|
if item.tax is not None:
|
||||||
price_with_tax = item.price + item.tax
|
price_with_tax = item.price + item.tax
|
||||||
item_dict.update({"price_with_tax": price_with_tax})
|
item_dict.update({"price_with_tax": price_with_tax})
|
||||||
|
|
|
||||||
|
|
@ -14,4 +14,4 @@ app = FastAPI()
|
||||||
|
|
||||||
@app.put("/items/{item_id}")
|
@app.put("/items/{item_id}")
|
||||||
async def update_item(item_id: int, item: Item):
|
async def update_item(item_id: int, item: Item):
|
||||||
return {"item_id": item_id, **item.dict()}
|
return {"item_id": item_id, **item.model_dump()}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ app = FastAPI()
|
||||||
|
|
||||||
@app.put("/items/{item_id}")
|
@app.put("/items/{item_id}")
|
||||||
async def update_item(item_id: int, item: Item, q: str | None = None):
|
async def update_item(item_id: int, item: Item, q: str | None = None):
|
||||||
result = {"item_id": item_id, **item.dict()}
|
result = {"item_id": item_id, **item.model_dump()}
|
||||||
if q:
|
if q:
|
||||||
result.update({"q": q})
|
result.update({"q": q})
|
||||||
return result
|
return result
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue