-
-
Save monkey-codes/35f44de8a77a35d9dffe11477434d880 to your computer and use it in GitHub Desktop.
Axon Aggregate
This file contains hidden or 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
| @Aggregate | |
| final class Waiter() { | |
| ... | |
| @CommandHandler | |
| constructor(command: HireWaiterCommand) : this() { | |
| AggregateLifecycle.apply(WaiterHiredEvent(id = command.id, name = command.name)) | |
| } | |
| @CommandHandler | |
| fun handle(command: TakeOrderCommand) { | |
| if(command.items.any { this.outOfStockItems.contains(it.name) }){ | |
| throw ItemsOutOfStockException(this.outOfStockItems.toList()) | |
| } | |
| AggregateLifecycle.apply(OrderTakenEvent(command.waiterId, command.orderId, items = command.items)) | |
| } | |
| @EventSourcingHandler | |
| fun on(event: WaiterHiredEvent) { | |
| this.id = event.id | |
| } | |
| @EventSourcingHandler | |
| fun on(event: OrderTakenEvent) { | |
| this.orders.add( Order(event.orderId, event.items)) | |
| } | |
| ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment