11#pylint: disable=unused-argument
22from __future__ import annotations
33from dataclasses import asdict
4- from typing import TYPE_CHECKING
5- from allocation .adapters import email , redis_eventpublisher
4+ from typing import Callable , TYPE_CHECKING
65from allocation .domain import commands , events , model
76from allocation .domain .model import OrderLine
87if TYPE_CHECKING :
@@ -38,6 +37,7 @@ def allocate(
3837 product .allocate (line )
3938 uow .commit ()
4039
40+
4141def reallocate (
4242 event : events .Deallocated , uow : unit_of_work .AbstractUnitOfWork
4343):
@@ -46,6 +46,7 @@ def reallocate(
4646 product .events .append (commands .Allocate (** asdict (event )))
4747 uow .commit ()
4848
49+
4950def change_batch_quantity (
5051 cmd : commands .ChangeBatchQuantity , uow : unit_of_work .AbstractUnitOfWork
5152):
@@ -58,18 +59,18 @@ def change_batch_quantity(
5859#pylint: disable=unused-argument
5960
6061def send_out_of_stock_notification (
61- event : events .OutOfStock , uow : unit_of_work . AbstractUnitOfWork ,
62+ event : events .OutOfStock , send_mail : Callable ,
6263):
63- email . send (
64+ send_mail (
6465 'stock@made.com' ,
6566 f'Out of stock for { event .sku } ' ,
6667 )
6768
6869
6970def publish_allocated_event (
70- event : events .Allocated , uow : unit_of_work . AbstractUnitOfWork ,
71+ event : events .Allocated , publish : Callable ,
7172):
72- redis_eventpublisher . publish ('line_allocated' , event )
73+ publish ('line_allocated' , event )
7374
7475
7576def add_allocation_to_read_model (
@@ -83,6 +84,7 @@ def add_allocation_to_read_model(
8384 )
8485 uow .commit ()
8586
87+
8688def remove_allocation_from_read_model (
8789 event : events .Deallocated , uow : unit_of_work .SqlAlchemyUnitOfWork ,
8890):
0 commit comments