Skip to content

Instantly share code, notes, and snippets.

@adriaanbd
Last active December 30, 2020 02:01
Show Gist options
  • Save adriaanbd/2291dd218f693cfbf8a8311683525831 to your computer and use it in GitHub Desktop.
Save adriaanbd/2291dd218f693cfbf8a8311683525831 to your computer and use it in GitHub Desktop.
From a service layer that uses a domain object (OrderLine) vs primitives
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
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
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