Skip to content

Instantly share code, notes, and snippets.

@AntonStoeckl
Created May 4, 2020 14:30
Show Gist options
  • Save AntonStoeckl/d94d0bd4996543903b2c8e9c26fae9fb to your computer and use it in GitHub Desktop.
Save AntonStoeckl/d94d0bd4996543903b2c8e9c26fae9fb to your computer and use it in GitHub Desktop.
Example for my iDDD with Go blog article series at https://medium.com/@TonyBologni
package customer
import (
"github.com/AntonStoeckl/go-iddd/service/customeraccounts/application/domain"
"github.com/AntonStoeckl/go-iddd/service/shared/es"
"github.com/cockroachdb/errors"
)
func ConfirmEmailAddress(eventStream es.EventStream, command domain.ConfirmCustomerEmailAddress) (es.RecordedEvents, error) {
customer := buildCurrentStateFrom(eventStream)
if err := assertNotDeleted(customer); err != nil {
return nil, errors.Wrap(err, "confirmEmailAddress")
}
if err := assertMatchingConfirmationHash(customer.emailAddressConfirmationHash, command.ConfirmationHash()); err != nil {
event := domain.BuildCustomerEmailAddressConfirmationFailed(
customer.id,
customer.emailAddress,
command.ConfirmationHash(),
err,
customer.currentStreamVersion+1,
)
return es.RecordedEvents{event}, nil
}
if customer.isEmailAddressConfirmed {
return nil, nil
}
event := domain.BuildCustomerEmailAddressConfirmed(
customer.id,
customer.emailAddress,
customer.currentStreamVersion+1,
)
return es.RecordedEvents{event}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment