11from datetime import datetime
22from flask import Flask , 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,20 +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+ uow = unit_of_work .SqlAlchemyUnitOfWork ()
33+ results = messagebus .handle (cmd , uow )
3234 batchref = results .pop (0 )
3335 except InvalidSku as e :
3436 return {"message" : str (e )}, 400
0 commit comments