📝 Update Request Body's `tutorial002` to deal with `tax=0` case (#13230)

Co-authored-by: svlandeg <svlandeg@github.com>
This commit is contained in:
Ysabel 2025-01-30 20:19:10 +08:00 committed by GitHub
parent 0541693bc7
commit 9667ce87a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -17,7 +17,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.dict()
if item.tax: 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})
return item_dict return item_dict

View File

@ -15,7 +15,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.dict()
if item.tax: 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})
return item_dict return item_dict