-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add identify_aggregate to command router (#133)
- Loading branch information
Showing
9 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
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
25 changes: 25 additions & 0 deletions
25
apps/one_piece_commanded/test/support/command_router_example/bank_account.ex
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule TestSupport.CommandRouterExample.BankAccount do | ||
@moduledoc false | ||
use OnePiece.Commanded.Aggregate, | ||
identifier: :uuid, | ||
stream_prefix: "bank-account2-" | ||
|
||
alias TestSupport.CommandRouterExample.{BankAccountOpened, BankAccountClosed} | ||
|
||
embedded_schema do | ||
field :closed?, :boolean, default: false | ||
end | ||
|
||
@impl OnePiece.Commanded.Aggregate | ||
def apply(aggregate, %BankAccountOpened{} = event) do | ||
aggregate | ||
|> Map.put(:uuid, event.uuid) | ||
end | ||
|
||
@impl OnePiece.Commanded.Aggregate | ||
def apply(aggregate, %BankAccountClosed{} = event) do | ||
aggregate | ||
|> Map.put(:uuid, event.uuid) | ||
|> Map.put(:closed?, true) | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
apps/one_piece_commanded/test/support/command_router_example/bank_account_closed.ex
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule TestSupport.CommandRouterExample.BankAccountClosed do | ||
@moduledoc false | ||
use OnePiece.Commanded.Event, aggregate_identifier: :uuid | ||
|
||
embedded_schema do | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
apps/one_piece_commanded/test/support/command_router_example/close_bank_account.ex
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule TestSupport.CommandRouterExample.CloseBankAccount do | ||
@moduledoc false | ||
use OnePiece.Commanded.CommandHandler | ||
|
||
use OnePiece.Commanded.Command, | ||
aggregate_identifier: :uuid | ||
|
||
alias TestSupport.CommandRouterExample.{ | ||
BankAccountClosed, | ||
CloseBankAccount, | ||
BankAccount | ||
} | ||
|
||
embedded_schema do | ||
end | ||
|
||
def handle(%BankAccount{} = _aggregate, %CloseBankAccount{} = command) do | ||
%BankAccountClosed{uuid: command.uuid} | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
apps/one_piece_commanded/test/support/command_router_example/command_router.ex
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
defmodule TestSupport.CommandRouterExample.CommandRouter do | ||
@moduledoc false | ||
use OnePiece.Commanded.CommandRouter | ||
|
||
identify_aggregate(TestSupport.CommandRouterExample.BankAccount) | ||
|
||
dispatch(TestSupport.CommandRouterExample.CloseBankAccount, | ||
to: TestSupport.CommandRouterExample.CloseBankAccount, | ||
aggregate: TestSupport.CommandRouterExample.BankAccount | ||
) | ||
|
||
register_transaction_script(TestSupport.CommandRouterExample.OpenBankAccount) | ||
end |