Skip to content

Commit

Permalink
Bump Dogma to v0.14.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Aug 17, 2024
1 parent 1f0e49d commit 368e0c8
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 61 deletions.
4 changes: 2 additions & 2 deletions cmd/bank/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
panic(err)
}

messages := []dogma.Message{
commands := []dogma.Command{
commands.OpenAccountForNewCustomer{
CustomerID: "cust1",
CustomerName: "Anna Smith",
Expand Down Expand Up @@ -68,7 +68,7 @@ func main() {
},
}

for _, m := range messages {
for _, m := range commands {
err := en.Dispatch(
context.Background(),
m,
Expand Down
6 changes: 3 additions & 3 deletions domain/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (a *account) hasSufficientFunds(amount int64) bool {
return a.Balance >= amount
}

func (a *account) ApplyEvent(m dogma.Message) {
func (a *account) ApplyEvent(m dogma.Event) {
switch x := m.(type) {
case events.AccountOpened:
a.Opened = true
Expand Down Expand Up @@ -102,7 +102,7 @@ func (AccountHandler) Configure(c dogma.AggregateConfigurer) {

// RouteCommandToInstance returns the ID of the aggregate instance that is
// targetted by m.
func (AccountHandler) RouteCommandToInstance(m dogma.Message) string {
func (AccountHandler) RouteCommandToInstance(m dogma.Command) string {
switch x := m.(type) {
case commands.OpenAccount:
return x.AccountID
Expand All @@ -119,7 +119,7 @@ func (AccountHandler) RouteCommandToInstance(m dogma.Message) string {
func (AccountHandler) HandleCommand(
r dogma.AggregateRoot,
s dogma.AggregateCommandScope,
m dogma.Message,
m dogma.Command,
) {
a := r.(*account)

Expand Down
6 changes: 3 additions & 3 deletions domain/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (c *customer) Acquire(s dogma.AggregateCommandScope, m commands.OpenAccount
})
}

func (c *customer) ApplyEvent(m dogma.Message) {
func (c *customer) ApplyEvent(m dogma.Event) {
switch m.(type) {
case events.CustomerAcquired:
c.Acquired = true
Expand Down Expand Up @@ -54,7 +54,7 @@ func (CustomerHandler) New() dogma.AggregateRoot {

// RouteCommandToInstance returns the ID of the aggregate instance that is
// targetted by m.
func (CustomerHandler) RouteCommandToInstance(m dogma.Message) string {
func (CustomerHandler) RouteCommandToInstance(m dogma.Command) string {
switch x := m.(type) {
case commands.OpenAccountForNewCustomer:
return x.CustomerID
Expand All @@ -67,7 +67,7 @@ func (CustomerHandler) RouteCommandToInstance(m dogma.Message) string {
func (CustomerHandler) HandleCommand(
r dogma.AggregateRoot,
s dogma.AggregateCommandScope,
m dogma.Message,
m dogma.Command,
) {
c := r.(*customer)

Expand Down
6 changes: 3 additions & 3 deletions domain/dailydebitlimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (d *dailyDebitLimit) wouldExceedLimit(amount int64) bool {
return d.TotalDebitsForDay+amount > maximumDailyDebitLimit
}

func (d *dailyDebitLimit) ApplyEvent(m dogma.Message) {
func (d *dailyDebitLimit) ApplyEvent(m dogma.Event) {
switch x := m.(type) {
case events.DailyDebitLimitConsumed:
d.TotalDebitsForDay = x.Amount
Expand Down Expand Up @@ -79,7 +79,7 @@ func (DailyDebitLimitHandler) Configure(c dogma.AggregateConfigurer) {

// RouteCommandToInstance returns the ID of the aggregate instance that is
// targetted by m.
func (DailyDebitLimitHandler) RouteCommandToInstance(m dogma.Message) string {
func (DailyDebitLimitHandler) RouteCommandToInstance(m dogma.Command) string {
switch x := m.(type) {
case commands.ConsumeDailyDebitLimit:
return fmt.Sprintf("%s:%s", x.Date, x.AccountID)
Expand All @@ -92,7 +92,7 @@ func (DailyDebitLimitHandler) RouteCommandToInstance(m dogma.Message) string {
func (DailyDebitLimitHandler) HandleCommand(
r dogma.AggregateRoot,
s dogma.AggregateCommandScope,
m dogma.Message,
m dogma.Command,
) {
d := r.(*dailyDebitLimit)

Expand Down
10 changes: 6 additions & 4 deletions domain/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
type DepositProcessHandler struct {
dogma.StatelessProcessBehavior
dogma.NoTimeoutMessagesBehavior
dogma.NoTimeoutHintBehavior
}

// Configure configures the behavior of the engine as it relates to this
Expand All @@ -33,7 +32,10 @@ func (DepositProcessHandler) Configure(c dogma.ProcessConfigurer) {

// RouteEventToInstance returns the ID of the process instance that is targetted
// by m.
func (DepositProcessHandler) RouteEventToInstance(_ context.Context, m dogma.Message) (string, bool, error) {
func (DepositProcessHandler) RouteEventToInstance(
_ context.Context,
m dogma.Event,
) (string, bool, error) {
switch x := m.(type) {
case events.DepositStarted:
return x.TransactionID, true, nil
Expand All @@ -49,9 +51,9 @@ func (DepositProcessHandler) RouteEventToInstance(_ context.Context, m dogma.Mes
// HandleEvent handles an event message that has been routed to this handler.
func (DepositProcessHandler) HandleEvent(
_ context.Context,
r dogma.ProcessRoot,
_ dogma.ProcessRoot,
s dogma.ProcessEventScope,
m dogma.Message,
m dogma.Event,
) error {
switch x := m.(type) {
case events.DepositStarted:
Expand Down
10 changes: 6 additions & 4 deletions domain/openaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
type OpenAccountForNewCustomerProcessHandler struct {
dogma.StatelessProcessBehavior
dogma.NoTimeoutMessagesBehavior
dogma.NoTimeoutHintBehavior
}

// Configure configures the behavior of the engine as it relates to this
Expand All @@ -29,7 +28,10 @@ func (OpenAccountForNewCustomerProcessHandler) Configure(c dogma.ProcessConfigur

// RouteEventToInstance returns the ID of the process instance that is targetted
// by m.
func (OpenAccountForNewCustomerProcessHandler) RouteEventToInstance(_ context.Context, m dogma.Message) (string, bool, error) {
func (OpenAccountForNewCustomerProcessHandler) RouteEventToInstance(
_ context.Context,
m dogma.Event,
) (string, bool, error) {
switch x := m.(type) {
case events.CustomerAcquired:
return x.CustomerID, true, nil
Expand All @@ -41,9 +43,9 @@ func (OpenAccountForNewCustomerProcessHandler) RouteEventToInstance(_ context.Co
// HandleEvent handles an event message that has been routed to this handler.
func (OpenAccountForNewCustomerProcessHandler) HandleEvent(
_ context.Context,
r dogma.ProcessRoot,
_ dogma.ProcessRoot,
s dogma.ProcessEventScope,
m dogma.Message,
m dogma.Event,
) error {
switch x := m.(type) {
case events.CustomerAcquired:
Expand Down
6 changes: 3 additions & 3 deletions domain/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (t *transaction) DeclineTransfer(s dogma.AggregateCommandScope, m commands.
})
}

func (t *transaction) ApplyEvent(m dogma.Message) {
func (t *transaction) ApplyEvent(m dogma.Event) {
switch m.(type) {
case events.DepositStarted:
t.Started = true
Expand Down Expand Up @@ -152,7 +152,7 @@ func (TransactionHandler) Configure(c dogma.AggregateConfigurer) {

// RouteCommandToInstance returns the ID of the aggregate instance that is
// targetted by m.
func (TransactionHandler) RouteCommandToInstance(m dogma.Message) string {
func (TransactionHandler) RouteCommandToInstance(m dogma.Command) string {
switch x := m.(type) {
case commands.Deposit:
return x.TransactionID
Expand Down Expand Up @@ -180,7 +180,7 @@ func (TransactionHandler) RouteCommandToInstance(m dogma.Message) string {
func (TransactionHandler) HandleCommand(
r dogma.AggregateRoot,
s dogma.AggregateCommandScope,
m dogma.Message,
m dogma.Command,
) {
t := r.(*transaction)

Expand Down
18 changes: 9 additions & 9 deletions domain/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ type transferProcess struct {

// TransferProcessHandler manages the process of transferring funds between
// accounts.
type TransferProcessHandler struct {
dogma.NoTimeoutHintBehavior
}
type TransferProcessHandler struct{}

// New returns a new transfer instance.
func (TransferProcessHandler) New() dogma.ProcessRoot {
Expand Down Expand Up @@ -54,7 +52,10 @@ func (TransferProcessHandler) Configure(c dogma.ProcessConfigurer) {

// RouteEventToInstance returns the ID of the process instance that is targetted
// by m.
func (TransferProcessHandler) RouteEventToInstance(_ context.Context, m dogma.Message) (string, bool, error) {
func (TransferProcessHandler) RouteEventToInstance(
_ context.Context,
m dogma.Event,
) (string, bool, error) {
switch x := m.(type) {
case events.TransferStarted:
return x.TransactionID, true, nil
Expand Down Expand Up @@ -82,7 +83,7 @@ func (TransferProcessHandler) HandleEvent(
_ context.Context,
r dogma.ProcessRoot,
s dogma.ProcessEventScope,
m dogma.Message,
m dogma.Event,
) error {
t := r.(*transferProcess)

Expand Down Expand Up @@ -157,8 +158,7 @@ func (TransferProcessHandler) HandleEvent(
})
}

case events.TransferApproved,
events.TransferDeclined:
case events.TransferApproved, events.TransferDeclined:
s.End()

default:
Expand All @@ -170,10 +170,10 @@ func (TransferProcessHandler) HandleEvent(

// HandleTimeout handles a timeout message that has been routed to this handler.
func (TransferProcessHandler) HandleTimeout(
ctx context.Context,
_ context.Context,
r dogma.ProcessRoot,
s dogma.ProcessTimeoutScope,
m dogma.Message,
m dogma.Timeout,
) error {
t := r.(*transferProcess)

Expand Down
10 changes: 6 additions & 4 deletions domain/withdrawal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
type WithdrawalProcessHandler struct {
dogma.StatelessProcessBehavior
dogma.NoTimeoutMessagesBehavior
dogma.NoTimeoutHintBehavior
}

// Configure configures the behavior of the engine as it relates to this
Expand All @@ -41,7 +40,10 @@ func (WithdrawalProcessHandler) Configure(c dogma.ProcessConfigurer) {

// RouteEventToInstance returns the ID of the process instance that is targetted
// by m.
func (WithdrawalProcessHandler) RouteEventToInstance(_ context.Context, m dogma.Message) (string, bool, error) {
func (WithdrawalProcessHandler) RouteEventToInstance(
_ context.Context,
m dogma.Event,
) (string, bool, error) {
switch x := m.(type) {
case events.WithdrawalStarted:
return x.TransactionID, true, nil
Expand All @@ -67,9 +69,9 @@ func (WithdrawalProcessHandler) RouteEventToInstance(_ context.Context, m dogma.
// HandleEvent handles an event message that has been routed to this handler.
func (WithdrawalProcessHandler) HandleEvent(
_ context.Context,
r dogma.ProcessRoot,
_ dogma.ProcessRoot,
s dogma.ProcessEventScope,
m dogma.Message,
m dogma.Event,
) error {
switch x := m.(type) {
case events.WithdrawalStarted:
Expand Down
19 changes: 13 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
module github.com/dogmatiq/example

go 1.21
go 1.23

toolchain go1.23.0

require (
github.com/dogmatiq/configkit v0.13.2
github.com/dogmatiq/dogma v0.13.1
github.com/dogmatiq/projectionkit v0.7.3
github.com/dogmatiq/configkit v0.13.6
github.com/dogmatiq/dogma v0.14.0
github.com/dogmatiq/projectionkit v0.7.4
github.com/dogmatiq/sqltest v0.3.0
github.com/dogmatiq/testkit v0.15.2
github.com/dogmatiq/testkit v0.16.0
github.com/mattn/go-sqlite3 v1.14.22
)

require (
github.com/dogmatiq/cosyne v0.2.0 // indirect
github.com/dogmatiq/dapper v0.5.3 // indirect
github.com/dogmatiq/iago v0.4.0 // indirect
github.com/dogmatiq/interopspec v0.5.4 // indirect
github.com/dogmatiq/jumble v0.1.0 // indirect
github.com/dogmatiq/linger v1.1.0 // indirect
github.com/go-sql-driver/mysql v1.5.0 // indirect
Expand All @@ -30,7 +33,11 @@ require (
github.com/lib/pq v1.10.2 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
Loading

0 comments on commit 368e0c8

Please sign in to comment.