11from datetime import datetime
22from flask import Flask , jsonify , request
3-
43from allocation .domain import commands
5- from allocation .adapters import orm
6- from allocation .service_layer import messagebus , unit_of_work
74from allocation .service_layer .handlers import InvalidSku
8- from allocation import views
5+ from allocation import bootstrap , views
96
107app = 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 {"message" : str (e )}, 400
3732
@@ -40,8 +35,7 @@ def allocate_endpoint():
4035
4136@app .route ("/allocations/<orderid>" , methods = ["GET" ])
4237def 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