Skip to content

Commit 2020b26

Browse files
committed
start on handler for change quantity [change_quantity_handler]
1 parent 0e8f68d commit 2020b26

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎src/allocation/service_layer/handlers.py‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
from __future__ import annotations
2-
import typing
2+
from typing import TYPE_CHECKING
3+
from allocation.adapters import email
34
from allocation.domain import events, model
45
from allocation.domain.model import OrderLine
5-
6-
if typing.TYPE_CHECKING:
6+
if TYPE_CHECKING:
77
from . import unit_of_work
88

99

1010
class InvalidSku(Exception):
1111
pass
1212

1313

14-
1514
def add_batch(
1615
event: events.BatchCreated, uow: unit_of_work.AbstractUnitOfWork
1716
):
@@ -39,6 +38,16 @@ def allocate(
3938
return batchref
4039

4140

41+
42+
def change_batch_quantity(
43+
event: events.BatchQuantityChanged, uow: unit_of_work.AbstractUnitOfWork
44+
):
45+
with uow:
46+
product = uow.products.get_by_batchref(batchref=event.ref)
47+
product.change_batch_quantity(ref=event.ref, qty=event.qty)
48+
uow.commit()
49+
50+
4251
# pylint: disable=unused-argument
4352

4453
def send_out_of_stock_notification(

‎src/allocation/service_layer/messagebus.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def handle(event: events.Event, uow: unit_of_work.AbstractUnitOfWork):
1717

1818
HANDLERS = {
1919
events.BatchCreated: [handlers.add_batch],
20+
events.BatchQuantityChanged: [handlers.change_batch_quantity],
2021
events.AllocationRequired: [handlers.allocate],
2122
events.OutOfStock: [handlers.send_out_of_stock_notification],
23+
2224
} # type: Dict[Type[events.Event], List[Callable]]

0 commit comments

Comments
 (0)