Skip to content

Commit 5919bd5

Browse files
committed
flask uses new bus [flask_initialises_bus]
1 parent f1fa974 commit 5919bd5

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/allocation/entrypoints/flask_app.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
from flask import Flask, jsonify, request
33

44
from allocation.domain import commands
5-
from allocation.adapters import orm
5+
from allocation.adapters import orm, email, redis_eventpublisher
66
from allocation.service_layer import messagebus, unit_of_work
77
from allocation.service_layer.handlers import InvalidSku
88
from allocation import views
99

1010
app = Flask(__name__)
1111
orm.start_mappers()
12+
uow = unit_of_work.SqlAlchemyUnitOfWork()
13+
bus = messagebus.MessageBus(
14+
uow=uow,
15+
send_mail=email.send,
16+
publish=redis_eventpublisher.publish
17+
)
18+
uow.bus = bus
19+
1220

1321

1422
@app.route("/add_batch", methods=['POST'])
@@ -19,8 +27,7 @@ def add_batch():
1927
cmd = commands.CreateBatch(
2028
request.json['ref'], request.json['sku'], request.json['qty'], eta,
2129
)
22-
uow = unit_of_work.SqlAlchemyUnitOfWork()
23-
messagebus.handle(cmd, uow)
30+
bus.handle(cmd)
2431
return 'OK', 201
2532

2633

@@ -30,8 +37,7 @@ def allocate_endpoint():
3037
cmd = commands.Allocate(
3138
request.json['orderid'], request.json['sku'], request.json['qty'],
3239
)
33-
uow = unit_of_work.SqlAlchemyUnitOfWork()
34-
messagebus.handle(cmd, uow)
40+
bus.handle(cmd)
3541
except InvalidSku as e:
3642
return jsonify({'message': str(e)}), 400
3743

@@ -40,8 +46,7 @@ def allocate_endpoint():
4046

4147
@app.route("/allocations/<orderid>", methods=['GET'])
4248
def allocations_view_endpoint(orderid):
43-
uow = unit_of_work.SqlAlchemyUnitOfWork()
44-
result = views.allocations(orderid, uow)
49+
result = views.allocations(orderid, bus.uow)
4550
if not result:
4651
return 'not found', 404
4752
return jsonify(result), 200

0 commit comments

Comments
 (0)