1
1
from datetime import datetime
2
2
from flask import Flask , jsonify , request
3
-
4
3
from allocation .domain import commands
5
- from allocation .adapters import orm
6
- from allocation .service_layer import messagebus , unit_of_work
7
4
from allocation .service_layer .handlers import InvalidSku
8
- from allocation import views
5
+ from allocation import bootstrap , views
9
6
10
7
app = Flask (__name__ )
11
- orm . start_mappers ()
8
+ bus = bootstrap . bootstrap ()
12
9
13
10
14
11
@app .route ("/add_batch" , methods = ['POST' ])
@@ -19,8 +16,7 @@ def add_batch():
19
16
cmd = commands .CreateBatch (
20
17
request .json ['ref' ], request .json ['sku' ], request .json ['qty' ], eta ,
21
18
)
22
- uow = unit_of_work .SqlAlchemyUnitOfWork ()
23
- messagebus .handle (cmd , uow )
19
+ bus .handle (cmd )
24
20
return 'OK' , 201
25
21
26
22
@@ -30,8 +26,7 @@ def allocate_endpoint():
30
26
cmd = commands .Allocate (
31
27
request .json ['orderid' ], request .json ['sku' ], request .json ['qty' ],
32
28
)
33
- uow = unit_of_work .SqlAlchemyUnitOfWork ()
34
- messagebus .handle (cmd , uow )
29
+ bus .handle (cmd )
35
30
except InvalidSku as e :
36
31
return jsonify ({'message' : str (e )}), 400
37
32
@@ -40,8 +35,7 @@ def allocate_endpoint():
40
35
41
36
@app .route ("/allocations/<orderid>" , methods = ['GET' ])
42
37
def allocations_view_endpoint (orderid ):
43
- uow = unit_of_work .SqlAlchemyUnitOfWork ()
44
- result = views .allocations (orderid , uow )
38
+ result = views .allocations (orderid , bus .uow )
45
39
if not result :
46
40
return 'not found' , 404
47
41
return jsonify (result ), 200
0 commit comments