From e7ecc7bff75197afd3f1f58c6d05da1f910da463 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Thu, 26 Jun 2025 08:41:38 +0800 Subject: [PATCH] Fix template --- templates/python/main.py | 20 +++++++++++++------- templates/templates.yaml | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/templates/python/main.py b/templates/python/main.py index 5951c0f..b183582 100644 --- a/templates/python/main.py +++ b/templates/python/main.py @@ -65,19 +65,24 @@ async def init(): # Get all customers @app.route('/api/customers', methods=['GET']) async def get_customers(): - customers_list: List[customers] = [] + customers_list: List[Customer] = [] async for customer in await customers.values(): customers_list.append(customer) return quart.Response(jsonpickle.encode(customers_list, unpicklable=False), mimetype="application/json") + # Create a person with JSON as body @app.route('/api/customers', methods=['POST']) async def create_customer(): - data = await request.get_json(force=True) - name: str = data['name'] - id: int = data['id'] - balance: float = data['balance'] + try: + data = await request.get_json(force=True) + name: str = data['name'] + id: int = int(data['id']) + balance: float = float(data['balance']) + except: + return quart.Response(f"Invalid JSON", status=400) + person: Customer = Customer(id, name, balance) await customers.put(person.id, person) @@ -87,6 +92,7 @@ async def create_customer(): mimetype='application/json' ) + # Get a single person @app.route('/api/customers/', methods=['GET']) async def get_person(id: str): @@ -118,7 +124,7 @@ def handle_event(e) -> None: oldValue = e.old print( - f"Event {e.type} for key={key}, new=${newValue}, old=${oldValue}") + f"Event {e.type} for key={key}, new={newValue}, old={oldValue}") def handle_delete_event(e) -> None: @@ -131,7 +137,7 @@ def handle_delete_event(e) -> None: oldValue = e.old print( - f"Event delete large balance for key={key}, old=${oldValue}") + f"Event delete large balance for key={key}, old={oldValue}") # ----- main ---------------------------------------------------------------- diff --git a/templates/templates.yaml b/templates/templates.yaml index b98da25..ac20b4e 100644 --- a/templates/templates.yaml +++ b/templates/templates.yaml @@ -115,6 +115,7 @@ templates: python main.py files: - main.py + - requirements.txt - name: go frameworkVersion: "coherence-go-client: v2.3.1"