11from datetime import datetime
22from flask import Flask , jsonify , request
33
4- from allocation .domain import events
4+ from allocation .domain import commands
55from allocation .adapters import orm
66from allocation .service_layer import messagebus , unit_of_work
77from allocation .service_layer .handlers import InvalidSku
@@ -15,21 +15,22 @@ def add_batch():
1515 eta = request .json ['eta' ]
1616 if eta is not None :
1717 eta = datetime .fromisoformat (eta ).date ()
18- event = events . BatchCreated (
18+ cmd = commands . CreateBatch (
1919 request .json ['ref' ], request .json ['sku' ], request .json ['qty' ], eta ,
2020 )
21- messagebus .handle (event , unit_of_work .SqlAlchemyUnitOfWork ())
21+ uow = unit_of_work .SqlAlchemyUnitOfWork ()
22+ messagebus .handle (cmd , uow )
2223 return 'OK' , 201
2324
2425
2526@app .route ("/allocate" , methods = ['POST' ])
2627def allocate_endpoint ():
2728 try :
28- event = events . AllocationRequired (
29+ cmd = commands . Allocate (
2930 request .json ['orderid' ], request .json ['sku' ], request .json ['qty' ],
3031 )
31- results = messagebus . handle ( event , unit_of_work .SqlAlchemyUnitOfWork () )
32- batchref = results . pop ( )
32+ uow = unit_of_work .SqlAlchemyUnitOfWork ()
33+ batchref = messagebus . handle ( cmd , uow )
3334 except InvalidSku as e :
3435 return jsonify ({'message' : str (e )}), 400
3536
0 commit comments