Skip to content

Commit 3e0e566

Browse files
committed
flask now uses commands [chapter_09_commands_ends]
1 parent fbf9393 commit 3e0e566

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/allocation/entrypoints/flask_app.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22
from flask import Flask, jsonify, request
33

4-
from allocation.domain import events
4+
from allocation.domain import commands
55
from allocation.adapters import orm
66
from allocation.service_layer import messagebus, unit_of_work
77
from allocation.service_layer.handlers import InvalidSku
@@ -15,21 +15,22 @@ def add_batch():
1515
eta = request.json['eta']
1616
if eta is not None:
1717
eta = datetime.fromisoformat(eta).date()
18-
event = events.BatchCreated(
18+
cmd = commands.CreateBatch(
1919
request.json['ref'], request.json['sku'], request.json['qty'], eta,
2020
)
21-
messagebus.handle(event, unit_of_work.SqlAlchemyUnitOfWork())
21+
uow = unit_of_work.SqlAlchemyUnitOfWork()
22+
messagebus.handle(cmd, uow)
2223
return 'OK', 201
2324

2425

2526
@app.route("/allocate", methods=['POST'])
2627
def allocate_endpoint():
2728
try:
28-
event = events.AllocationRequired(
29+
cmd = commands.Allocate(
2930
request.json['orderid'], request.json['sku'], request.json['qty'],
3031
)
31-
results = messagebus.handle(event, unit_of_work.SqlAlchemyUnitOfWork())
32-
batchref = results.pop()
32+
uow = unit_of_work.SqlAlchemyUnitOfWork()
33+
batchref = messagebus.handle(cmd, uow)
3334
except InvalidSku as e:
3435
return jsonify({'message': str(e)}), 400
3536

0 commit comments

Comments
 (0)