mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-17 06:58:09 +01:00
Rename get_order_status to get_order, add ecommerce list orders goal
This commit is contained in:
30
tools/ecommerce/list_orders.py
Normal file
30
tools/ecommerce/list_orders.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
def sorting(e):
|
||||
return e['order_date']
|
||||
|
||||
def list_orders(args: dict) -> dict:
|
||||
|
||||
email_address = args.get("email_address")
|
||||
|
||||
file_path = Path(__file__).resolve().parent.parent / "data" / "customer_order_data.json"
|
||||
if not file_path.exists():
|
||||
return {"error": "Data file not found."}
|
||||
|
||||
with open(file_path, "r") as file:
|
||||
data = json.load(file)
|
||||
order_list = data["orders"]
|
||||
|
||||
rtn_order_list = []
|
||||
for order in order_list:
|
||||
if order["email"] == email_address:
|
||||
rtn_order_list.append(order)
|
||||
|
||||
if len(rtn_order_list) > 0:
|
||||
rtn_order_list.sort(key=sorting)
|
||||
return {"orders": rtn_order_list}
|
||||
else:
|
||||
return_msg = "No orders for customer " + email_address + " found."
|
||||
return {"error": return_msg}
|
||||
|
||||
Reference in New Issue
Block a user