mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-10-07 06:58:54 +00:00
Fix shared layer structure and DynamoDB Decimal type error (#2)
Move shared layer source from src/shared/python/shared/ to src/shared/shared/ to prevent SAM from creating a double python/python/ directory in the layer artifact. Add _to_decimal() helper to convert floats to Decimal for DynamoDB compatibility in put_order.
This commit is contained in:
parent
d332affd56
commit
360a0435e8
4 changed files with 9 additions and 2 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from decimal import Decimal
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
from boto3.dynamodb.conditions import Key
|
from boto3.dynamodb.conditions import Key
|
||||||
import boto3
|
import boto3
|
||||||
|
|
@ -63,8 +65,13 @@ def get_form_status(week: str) -> str:
|
||||||
return menu.get("form_status", "closed")
|
return menu.get("form_status", "closed")
|
||||||
|
|
||||||
|
|
||||||
|
def _to_decimal(obj):
|
||||||
|
"""Convert floats to Decimal for DynamoDB compatibility."""
|
||||||
|
return json.loads(json.dumps(obj), parse_float=Decimal)
|
||||||
|
|
||||||
|
|
||||||
def put_order(week: str, employee_slug: str, order_data: dict):
|
def put_order(week: str, employee_slug: str, order_data: dict):
|
||||||
_get_table().put_item(Item={
|
_get_table().put_item(Item=_to_decimal({
|
||||||
"PK": f"WEEK#{week}",
|
"PK": f"WEEK#{week}",
|
||||||
"SK": f"ORDER#{employee_slug}",
|
"SK": f"ORDER#{employee_slug}",
|
||||||
"employee_name": order_data["employee_name"],
|
"employee_name": order_data["employee_name"],
|
||||||
|
|
@ -73,7 +80,7 @@ def put_order(week: str, employee_slug: str, order_data: dict):
|
||||||
"items": order_data["items"],
|
"items": order_data["items"],
|
||||||
"total": order_data["total"],
|
"total": order_data["total"],
|
||||||
"ttl": ttl_days(90),
|
"ttl": ttl_days(90),
|
||||||
})
|
}))
|
||||||
|
|
||||||
|
|
||||||
def get_orders(week: str) -> list[dict]:
|
def get_orders(week: str) -> list[dict]:
|
||||||
Loading…
Add table
Reference in a new issue