Skip to content

Commit 8b3eeed

Browse files
committed
use bootstrap in flask [flask_calls_bootstrap]
1 parent e235b21 commit 8b3eeed

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
from datetime import datetime
22
from flask import Flask, jsonify, request
3-
43
from allocation.domain import commands
5-
from allocation.adapters import orm
6-
from allocation.service_layer import messagebus, unit_of_work
74
from allocation.service_layer.handlers import InvalidSku
8-
from allocation import views
5+
from allocation import bootstrap, views
96

107
app = Flask(__name__)
11-
orm.start_mappers()
8+
bus = bootstrap.bootstrap()
129

1310

1411
@app.route("/add_batch", methods=['POST'])
@@ -19,8 +16,7 @@ def add_batch():
1916
cmd = commands.CreateBatch(
2017
request.json['ref'], request.json['sku'], request.json['qty'], eta,
2118
)
22-
uow = unit_of_work.SqlAlchemyUnitOfWork()
23-
messagebus.handle(cmd, uow)
19+
bus.handle(cmd)
2420
return 'OK', 201
2521

2622

@@ -30,8 +26,7 @@ def allocate_endpoint():
3026
cmd = commands.Allocate(
3127
request.json['orderid'], request.json['sku'], request.json['qty'],
3228
)
33-
uow = unit_of_work.SqlAlchemyUnitOfWork()
34-
messagebus.handle(cmd, uow)
29+
bus.handle(cmd)
3530
except InvalidSku as e:
3631
return jsonify({'message': str(e)}), 400
3732

@@ -40,8 +35,7 @@ def allocate_endpoint():
4035

4136
@app.route("/allocations/<orderid>", methods=['GET'])
4237
def allocations_view_endpoint(orderid):
43-
uow = unit_of_work.SqlAlchemyUnitOfWork()
44-
result = views.allocations(orderid, uow)
38+
result = views.allocations(orderid, bus.uow)
4539
if not result:
4640
return 'not found', 404
4741
return jsonify(result), 200

0 commit comments

Comments
 (0)