Skip to content

Commit

Permalink
Return price as a float instead of a string from product service. Thi…
Browse files Browse the repository at this point in the history
…s changed in recent PR, which broke the frontend (aws-samples#545)
  • Loading branch information
gfaires authored Feb 8, 2024
1 parent 7f4e50f commit c7e6743
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/products/src/products_service/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def update_product(original_product, updated_product):
validate_product(updated_product)
current_app.logger.debug(f"Updating product: {original_product} to {updated_product}")
dynamodb.products.upsert(updated_product)
cast_price(updated_product)

def update_inventory_delta(product, stock_delta):
if product['current_stock'] + stock_delta < 0:
Expand All @@ -95,6 +96,7 @@ def add_product(product):
product.update(product_temp)
validate_product(product)
dynamodb.products.upsert(product)
cast_price(product)

def delete_product(self, product):
dynamodb.products.delete(product['id'])
Expand Down Expand Up @@ -144,7 +146,7 @@ def update_product_template(product, fully_qualify_image_urls):
if 'sk' not in product or product['sk'] is None:
product['sk'] = ''
product['current_stock'] = int(product['current_stock'])
product['price'] = str(product['price'])
cast_price(product)
if 'promoted' in product:
product['promoted'] = str(product['promoted'])
set_product_url(product)
Expand Down Expand Up @@ -178,6 +180,10 @@ def set_category_url(category, fully_qualify_image_urls):
elif not category.get("image") or category["image"] == missing_image_file:
category["image"] = f"{current_app.config['IMAGE_ROOT_URL']}{missing_image_file}"

def cast_price(product):
# Cast the price from a string back to a float for the frontend
product['price'] = float(product['price'])

def init():
dynamodb.init_tables()
no_categories = load_categories()
Expand Down
10 changes: 5 additions & 5 deletions src/products/test/integ/json_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"style": {"type": "string"},
"description": {"type": "string"},
"aliases": {"type": ["array", "null"]},
"price": {"type": "string"},
"price": {"type": "number"},
"image": {"type": "string"},
"current_stock": {"type": "number"},
"promoted": {"type": "string"}
Expand All @@ -32,7 +32,7 @@
"style": {"type": "string"},
"description": {"type": "string"},
"aliases": {"type": ["array", "null"]},
"price": {"type": "string"},
"price": {"type": "number"},
"image": {"type": "string"},
"featured": {"type": "string"},
"current_stock": {"type": "number"},
Expand All @@ -53,7 +53,7 @@
"style": {"type": "string"},
"description": {"type": "string"},
"aliases": {"type": ["array", "null"]},
"price": {"type": "string"},
"price": {"type": "number"},
"image": {"type": "string"},
"featured": {"type": "string"},
"gender_affinity": {"type": "string"},
Expand All @@ -76,7 +76,7 @@
"style": {"type": "string"},
"description": {"type": "string"},
"aliases": {"type": ["array", "null"]},
"price": {"type": "string"},
"price": {"type": "number"},
"image": {"type": "string"},
"current_stock": {"type": "number"},
"promoted": {"type": "string"}
Expand Down Expand Up @@ -120,7 +120,7 @@
"style": {"type": "string"},
"description": {"type": "string"},
"aliases": {"type": ["array", "null"]},
"price": {"type": "string"},
"price": {"type": "number"},
"image": {"type": "string"},
"featured": {"type": "string"},
"gender_affinity": {"type": "string"},
Expand Down

0 comments on commit c7e6743

Please sign in to comment.