Skip to content

Commit 011d640

Browse files
committed
handler for view model update
1 parent 7e58f4b commit 011d640

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/allocation/service_layer/handlers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,18 @@ def publish_allocated_event(
6666
uow: unit_of_work.AbstractUnitOfWork,
6767
):
6868
redis_eventpublisher.publish("line_allocated", event)
69+
70+
71+
def add_allocation_to_read_model(
72+
event: events.Allocated,
73+
uow: unit_of_work.SqlAlchemyUnitOfWork,
74+
):
75+
with uow:
76+
uow.session.execute(
77+
"""
78+
INSERT INTO allocations_view (orderid, sku, batchref)
79+
VALUES (:orderid, :sku, :batchref)
80+
""",
81+
dict(orderid=event.orderid, sku=event.sku, batchref=event.batchref),
82+
)
83+
uow.commit()

src/allocation/views.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
def allocations(orderid: str, uow: unit_of_work.SqlAlchemyUnitOfWork):
55
with uow:
6-
results = list(
7-
uow.session.execute(
8-
"SELECT sku, batchref FROM allocations_view WHERE orderid = :orderid",
9-
dict(orderid=orderid),
10-
)
6+
results = uow.session.execute(
7+
"""
8+
SELECT sku, batchref FROM allocations_view WHERE orderid = :orderid
9+
""",
10+
dict(orderid=orderid),
1111
)
1212
return [dict(r) for r in results]

0 commit comments

Comments
 (0)