2022-05-14 06:59:59 -05:00
|
|
|
from typing import Union
|
2020-06-28 20:13:30 +02:00
|
|
|
|
2018-12-18 21:59:06 +04:00
|
|
|
from fastapi import FastAPI
|
2018-12-18 22:36:04 +04:00
|
|
|
from pydantic import BaseModel
|
2018-12-18 21:59:06 +04:00
|
|
|
|
2018-12-13 21:48:37 +04:00
|
|
|
|
2018-12-13 21:05:15 +04:00
|
|
|
class Item(BaseModel):
|
|
|
|
|
name: str
|
2022-05-14 06:59:59 -05:00
|
|
|
description: Union[str, None] = None
|
2018-12-13 21:05:15 +04:00
|
|
|
price: float
|
2022-05-14 06:59:59 -05:00
|
|
|
tax: Union[float, None] = None
|
2018-12-13 21:05:15 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
2018-12-13 21:48:37 +04:00
|
|
|
|
2018-12-13 21:25:45 +04:00
|
|
|
@app.post("/items/")
|
|
|
|
|
async def create_item(item: Item):
|
|
|
|
|
item_dict = item.dict()
|
2025-01-30 20:19:10 +08:00
|
|
|
if item.tax is not None:
|
2018-12-13 21:25:45 +04:00
|
|
|
price_with_tax = item.price + item.tax
|
|
|
|
|
item_dict.update({"price_with_tax": price_with_tax})
|
|
|
|
|
return item_dict
|