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
class Order { | |
protected whenOrderCreated(event: OrderCreated): void { | |
// setting the other properies as before | |
// The event now contains the exchangeRate captured at the moment that the order was created | |
this._chargedAmount = event.amount * event.exchangeRate; | |
} | |
} |
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
class Order { | |
protected whenOrderCreated(event: OrderCreated): void { | |
// setting the other properies as before | |
exchangeRate = exchangeRateToCurrency[event.currency]; | |
this._chargedAmount = event.amount * exchangeRate; | |
} | |
} |
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
class Order { | |
// If it is the repository that is triggering the reconstruction it would use a version converter | |
protected whenOrderCreated(event: OrderCreated): void { | |
this._items = event.items; | |
this._status = OrderStatus.OPEN; | |
this._amount = event.amount; | |
this._destination = event.destination; | |
this._customerId = event.customerId; |
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
class Order { | |
protected whenOrderCreated(event: OrderCreated): void { | |
this._items = event.items; | |
this._status = OrderStatus.OPEN; | |
this._amount = event.amount; | |
this._destination = event.destination; | |
this._customerId = event.customerId; | |
// New code - detect if we have the property first | |
if (event.hasOwnProperty('deliveryMethod') { |
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
class Order { | |
protected whenOrderCreated(event: OrderCreated): void { | |
this._items = event.items; | |
this._status = OrderStatus.OPEN; | |
this._amount = event.amount; | |
this._destination = event.destination; | |
this._customerId = event.customerId; | |
// New code | |
this.deliveryMethod = event.deliveryMethod; |
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
class DeclineProjector: | |
def __init__(self, projection: DeclineProjection): | |
self.projection = projection | |
@method_dispatch | |
def apply(self, event: DomainEvent): | |
pass | |
@apply.register(PaymentDeclined) | |
def _(self, event: PaymentDeclined): |
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
class PaymentProjection: | |
def __init__(self, repository: PaymentViewRepository): | |
self.repository = repository | |
def boot(self) -> bool: | |
return self.repository.initialize() | |
def create_payment(self, payment_id: str, status: str, amount_due: float, last_updated_at: str): | |
payment_view = PaymentView( | |
payment_id=payment_id, |
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
class PaymentProjector: | |
def __init__(self, projection: PaymentProjection): | |
self.projection = projection | |
@method_dispatch | |
def apply(self, event: DomainEvent): | |
raise ValueError('Unknown event!') | |
@apply.register(PaymentCreated) | |
def _(self, event: PaymentCreated): |
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
class Projectionist: | |
def __init__(self, projector: PaymentProjector, stream_service: PaymentStreamService, | |
ledger_repository: LedgerRepository, ledger_name: str): | |
self.projector = projector | |
self.stream_service = stream_service | |
self.ledger_repository = ledger_repository | |
self.ledger = None | |
self.ledger_name = ledger_name | |
async def start(self): |
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
async def import_stream(): | |
projectionist = PaymentProjectionist( | |
projector=projector, stream_service=stream_service, | |
ledger_repository=ledger_repository, ledger_name=PAYMENT_PROJECTION | |
) | |
await projectionist.start() |
NewerOlder