Skip to content

Commit c2bbd9f

Browse files
committed
putting it in the services layer isn't lovely either [email_in_services]
1 parent 60ed42a commit c2bbd9f

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/allocation/domain/model.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from dataclasses import dataclass
33
from datetime import date
44
from typing import Optional, List, Set
5-
from allocation.adapters import email
65

76

87
class OutOfStock(Exception):
@@ -25,7 +24,6 @@ def allocate(self, line: OrderLine) -> str:
2524
self.version_number += 1
2625
return batch.reference
2726
except StopIteration:
28-
email.send_mail('[email protected]', f'Out of stock for {line.sku}')
2927
raise OutOfStock(f'Out of stock for sku {line.sku}')
3028

3129

@@ -82,4 +80,3 @@ def available_quantity(self) -> int:
8280

8381
def can_allocate(self, line: OrderLine) -> bool:
8482
return self.sku == line.sku and self.available_quantity >= line.qty
85-

src/allocation/service_layer/services.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Optional
33
from datetime import date
44

5+
from allocation.adapters import email
56
from allocation.domain import model
67
from allocation.domain.model import OrderLine
78
from allocation.service_layer import unit_of_work
@@ -33,6 +34,10 @@ def allocate(
3334
product = uow.products.get(sku=line.sku)
3435
if product is None:
3536
raise InvalidSku(f'Invalid sku {line.sku}')
36-
batchref = product.allocate(line)
37-
uow.commit()
38-
return batchref
37+
try:
38+
batchref = product.allocate(line)
39+
uow.commit()
40+
return batchref
41+
except model.OutOfStock:
42+
email.send_mail('[email protected]', f'Out of stock for {line.sku}')
43+
raise

0 commit comments

Comments
 (0)