11from datetime import datetime
22from 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
55app = Flask (__name__ )
66orm .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' ])
2223def 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