Created
May 4, 2020 14:30
-
-
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
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
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