Created
May 4, 2020 14:26
-
-
Save AntonStoeckl/34244fb5bdee9533966180e0fc631e4b 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 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
package customer | |
import ( | |
"github.com/AntonStoeckl/go-iddd/service/customeraccounts/application/domain" | |
"github.com/AntonStoeckl/go-iddd/service/customeraccounts/application/domain/customer/value" | |
"github.com/AntonStoeckl/go-iddd/service/shared/es" | |
) | |
type currentState struct { | |
id value.CustomerID | |
personName value.PersonName | |
emailAddress value.EmailAddress | |
emailAddressConfirmationHash value.ConfirmationHash | |
isEmailAddressConfirmed bool | |
isDeleted bool | |
currentStreamVersion uint | |
} | |
func buildCurrentStateFrom(eventStream es.EventStream) currentState { | |
customer := currentState{} | |
for _, event := range eventStream { | |
switch actualEvent := event.(type) { | |
case domain.CustomerRegistered: | |
customer.id = actualEvent.CustomerID() | |
customer.personName = actualEvent.PersonName() | |
customer.emailAddress = actualEvent.EmailAddress() | |
customer.emailAddressConfirmationHash = actualEvent.ConfirmationHash() | |
case domain.CustomerEmailAddressConfirmed: | |
customer.isEmailAddressConfirmed = true | |
case domain.CustomerEmailAddressChanged: | |
customer.emailAddress = actualEvent.EmailAddress() | |
customer.emailAddressConfirmationHash = actualEvent.ConfirmationHash() | |
customer.isEmailAddressConfirmed = false | |
case domain.CustomerNameChanged: | |
customer.personName = actualEvent.PersonName() | |
case domain.CustomerDeleted: | |
customer.isDeleted = true | |
} | |
customer.currentStreamVersion = event.Meta().StreamVersion() | |
} | |
return customer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment