Added barcode to products
This commit is contained in:
parent
8e227fed84
commit
de974e76e2
3 changed files with 12 additions and 7 deletions
|
|
@ -3,4 +3,5 @@ from pydantic import BaseModel, HttpUrl
|
|||
class Product(BaseModel):
|
||||
name: str
|
||||
price: float
|
||||
barcode: int
|
||||
image_url: HttpUrl
|
||||
|
|
@ -1,9 +1,14 @@
|
|||
from src.classes import product_classes
|
||||
|
||||
apple = product_classes.Product(name="Appel", price=1.0, image_url="https://i.etsystatic.com/16348658/r/il/380709/1340147432/il_570xN.1340147432_p3pc.jpg")
|
||||
bubble_tea = product_classes.Product(name="Bubble Tea", price=5.0, image_url="https://uxwing.com/wp-content/themes/uxwing/download/food-and-drinks/bubble-tea-icon.png")
|
||||
apple = product_classes.Product(name="Appel", price=1.0, barcode=1000 , image_url="https://i.etsystatic.com/16348658/r/il/380709/1340147432/il_570xN.1340147432_p3pc.jpg")
|
||||
bubble_tea = product_classes.Product(name="Bubble Tea", price=5.0, barcode=1001 ,image_url="https://uxwing.com/wp-content/themes/uxwing/download/food-and-drinks/bubble-tea-icon.png")
|
||||
|
||||
product_list = [apple, bubble_tea]
|
||||
|
||||
def get_all_products() -> list[product_classes.Product]:
|
||||
return product_list
|
||||
|
||||
def get_single_product(barcode: int) -> product_classes.Product:
|
||||
for product in product_list:
|
||||
if product.barcode == barcode:
|
||||
return product
|
||||
|
|
@ -26,7 +26,6 @@ def read_root():
|
|||
def get_all_products():
|
||||
return data_connection.get_all_products()
|
||||
|
||||
# @app.get("/boardgames/{boardgame_id}", response_model=boardgame_classes.BoardGame)
|
||||
# def get_boardgame_by_id(boardgame_id: int):
|
||||
# requested_boardgame: boardgame_classes.BoardGame = data_connection.get_boardgame(boardgame_id)
|
||||
# return requested_boardgame
|
||||
@app.get("/products/{barcode}", response_model=product_classes.Product)
|
||||
def get_single_product(barcode: int):
|
||||
return data_connection.get_single_product(barcode)
|
||||
Loading…
Reference in a new issue