Skip to content

Commit e7ecc7b

Browse files
author
Tim Middleton
committed
Fix template
1 parent 34dc02c commit e7ecc7b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

templates/python/main.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,24 @@ async def init():
6565
# Get all customers
6666
@app.route('/api/customers', methods=['GET'])
6767
async def get_customers():
68-
customers_list: List[customers] = []
68+
customers_list: List[Customer] = []
6969
async for customer in await customers.values():
7070
customers_list.append(customer)
7171

7272
return quart.Response(jsonpickle.encode(customers_list, unpicklable=False), mimetype="application/json")
7373

74+
7475
# Create a person with JSON as body
7576
@app.route('/api/customers', methods=['POST'])
7677
async def create_customer():
77-
data = await request.get_json(force=True)
78-
name: str = data['name']
79-
id: int = data['id']
80-
balance: float = data['balance']
78+
try:
79+
data = await request.get_json(force=True)
80+
name: str = data['name']
81+
id: int = int(data['id'])
82+
balance: float = float(data['balance'])
83+
except:
84+
return quart.Response(f"Invalid JSON", status=400)
85+
8186
person: Customer = Customer(id, name, balance)
8287
await customers.put(person.id, person)
8388

@@ -87,6 +92,7 @@ async def create_customer():
8792
mimetype='application/json'
8893
)
8994

95+
9096
# Get a single person
9197
@app.route('/api/customers/<id>', methods=['GET'])
9298
async def get_person(id: str):
@@ -118,7 +124,7 @@ def handle_event(e) -> None:
118124
oldValue = e.old
119125

120126
print(
121-
f"Event {e.type} for key={key}, new=${newValue}, old=${oldValue}")
127+
f"Event {e.type} for key={key}, new={newValue}, old={oldValue}")
122128

123129

124130
def handle_delete_event(e) -> None:
@@ -131,7 +137,7 @@ def handle_delete_event(e) -> None:
131137
oldValue = e.old
132138

133139
print(
134-
f"Event delete large balance for key={key}, old=${oldValue}")
140+
f"Event delete large balance for key={key}, old={oldValue}")
135141

136142

137143
# ----- main ----------------------------------------------------------------

templates/templates.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ templates:
115115
python main.py
116116
files:
117117
- main.py
118+
- requirements.txt
118119

119120
- name: go
120121
frameworkVersion: "coherence-go-client: v2.3.1"

0 commit comments

Comments
 (0)