Skip to content

Commit 341827e

Browse files
committed
flask now uses commands [chapter_09_commands_ends]
1 parent 2917af4 commit 341827e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/allocation/flask_app.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22
from flask import Flask, jsonify, request
3-
from allocation import events, exceptions, messagebus, orm, unit_of_work
3+
from allocation import commands, exceptions, messagebus, orm, unit_of_work
44

55
app = Flask(__name__)
66
orm.start_mappers()
@@ -11,21 +11,22 @@ def add_batch():
1111
eta = request.json['eta']
1212
if eta is not None:
1313
eta = datetime.fromisoformat(eta).date()
14-
event = events.BatchCreated(
14+
cmd = commands.CreateBatch(
1515
request.json['ref'], request.json['sku'], request.json['qty'], eta,
1616
)
17-
messagebus.handle(event, unit_of_work.SqlAlchemyUnitOfWork())
17+
uow = unit_of_work.SqlAlchemyUnitOfWork()
18+
messagebus.handle(cmd, uow)
1819
return 'OK', 201
1920

2021

2122
@app.route("/allocate", methods=['POST'])
2223
def allocate_endpoint():
2324
try:
24-
event = events.AllocationRequired(
25+
cmd = commands.Allocate(
2526
request.json['orderid'], request.json['sku'], request.json['qty'],
2627
)
27-
results = messagebus.handle(event, unit_of_work.SqlAlchemyUnitOfWork())
28-
batchref = results.pop()
28+
uow = unit_of_work.SqlAlchemyUnitOfWork()
29+
batchref = messagebus.handle(cmd, uow)
2930
except exceptions.InvalidSku as e:
3031
return jsonify({'message': str(e)}), 400
3132

0 commit comments

Comments
 (0)