Last active
December 30, 2020 02:01
-
-
Save adriaanbd/2291dd218f693cfbf8a8311683525831 to your computer and use it in GitHub Desktop.
From a service layer that uses a domain object (OrderLine) vs primitives
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def allocate(orderid:str, sku: str, qty: int, repo: AbstractRepository, session) -> str: | |
""" | |
Obtains a list of Batches from data layer, validates OrderLine, | |
calls the allocate domain service, and commits to database. | |
""" | |
batches = repo.list() | |
if not is_valid_sku(sku, batches): | |
raise InvalidSKU(f'Invalid SKU: {sku}') | |
ref = model.allocate(orderid, sku, qty, batches) | |
session.commit() | |
return ref |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def allocate(orderid:str, sku: str, qty: int, repo: AbstractRepository, session) -> str: | |
""" | |
Obtains a list of Batches from data layer, validates OrderLine, | |
calls the allocate domain service, and commits to database. | |
""" | |
batches = repo.list() | |
if not is_valid_sku(sku, batches): | |
raise InvalidSKU(f'Invalid SKU: {sku}') | |
line = model.OrderLine(orderid, sku, qty) | |
ref = model.allocate(line, batches) | |
session.commit() | |
return ref |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def allocate(line: model.OrderLine, repo: AbstractRepository, session) -> str: | |
""" | |
Obtains a list of Batches from data layer, validates OrderLine, | |
calls the allocate domain service, and commits to database. | |
""" | |
batches = repo.list() | |
if not is_valid_sku(line, batches): | |
raise InvalidSKU(f'Invalid SKU: {line.sku}') | |
ref = model.allocate(line, batches) | |
session.commit() | |
return ref |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment