Skip to content

Commit 680ad15

Browse files
committed
handlers now have all and only explicit dependencies [handler_with_explicit_dependency]
1 parent 5ce56a0 commit 680ad15

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/allocation/service_layer/handlers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#pylint: disable=unused-argument
22
from __future__ import annotations
33
from dataclasses import asdict
4-
from typing import TYPE_CHECKING
5-
from allocation.adapters import email, redis_eventpublisher
4+
from typing import Callable, TYPE_CHECKING
65
from allocation.domain import commands, events, model
76
from allocation.domain.model import OrderLine
87
if TYPE_CHECKING:
@@ -38,6 +37,7 @@ def allocate(
3837
product.allocate(line)
3938
uow.commit()
4039

40+
4141
def 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+
4950
def 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

6061
def 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
6566
f'Out of stock for {event.sku}',
6667
)
6768

6869

6970
def 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

7576
def add_allocation_to_read_model(
@@ -83,6 +84,7 @@ def add_allocation_to_read_model(
8384
)
8485
uow.commit()
8586

87+
8688
def remove_allocation_from_read_model(
8789
event: events.Deallocated, uow: unit_of_work.SqlAlchemyUnitOfWork,
8890
):

0 commit comments

Comments
 (0)