Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions templates/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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


# Get a single person
@app.route('/api/customers/<id>', methods=['GET'])
async def get_person(id: str):
Expand Down Expand Up @@ -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:
Expand All @@ -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 ----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions templates/templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ templates:
python main.py
files:
- main.py
- requirements.txt

- name: go
frameworkVersion: "coherence-go-client: v2.3.1"
Expand Down
Loading