Documentation ¶
Overview ¶
Package user holds user domain logic
Package user holds user domain logic
Index ¶
- Constants
- Variables
- func NewCommandFromPayload(contract string, payload []byte) (domain.Command, error)
- func OnChangeEmailAddress(repository Repository, db *sql.DB) commandbus.CommandHandler
- func OnRegisterWithEmail(repository Repository, db *sql.DB) commandbus.CommandHandler
- func OnRegisterWithFacebook(repository Repository, db *sql.DB) commandbus.CommandHandler
- func OnRegisterWithGoogle(repository Repository, db *sql.DB) commandbus.CommandHandler
- func OnRequestAccessToken(repository Repository, db *sql.DB) commandbus.CommandHandler
- type AccessTokenWasRequested
- type ChangeEmailAddress
- type ConnectedWithFacebook
- type ConnectedWithGoogle
- type EmailAddress
- type EmailAddressWasChanged
- type RegisterWithEmail
- type RegisterWithFacebook
- type RegisterWithGoogle
- type Repository
- type RequestAccessToken
- type User
- func (u *User) ChangeEmailAddress(email EmailAddress) error
- func (u User) Changes() []domain.Event
- func (u *User) ConnectWithFacebook(facebookID string) error
- func (u *User) ConnectWithGoogle(googleID string) error
- func (u User) ID() uuid.UUID
- func (u *User) RegisterWithEmail(id uuid.UUID, email EmailAddress) error
- func (u *User) RegisterWithFacebook(id uuid.UUID, email EmailAddress, facebookID string) error
- func (u *User) RegisterWithGoogle(id uuid.UUID, email EmailAddress, googleID string) error
- func (u *User) RequestAccessToken() error
- func (u User) Version() int
- type WasRegisteredWithEmail
- type WasRegisteredWithFacebook
- type WasRegisteredWithGoogle
Constants ¶
const ( // RequestUserAccessToken command bus contract RequestUserAccessToken = "request-user-access-token" // ChangeUserEmailAddress command bus contract ChangeUserEmailAddress = "change-user-email-address" // RegisterUserWithEmail command bus contract RegisterUserWithEmail = "register-user-with-email" // RegisterUserWithFacebook command bus contract RegisterUserWithFacebook = "register-user-with-facebook" // RegisterUserWithGoogle command bus contract RegisterUserWithGoogle = "register-user-with-google" )
Variables ¶
var ErrAlreadyRegistered = fmt.Errorf("user is already registered")
ErrAlreadyRegistered is when user with given email already exist.
var StreamName = fmt.Sprintf("%T", User{})
StreamName for user domain
Functions ¶
func NewCommandFromPayload ¶
NewCommandFromPayload builds command by contract from json payload
func OnChangeEmailAddress ¶
func OnChangeEmailAddress(repository Repository, db *sql.DB) commandbus.CommandHandler
OnChangeEmailAddress creates command handler
func OnRegisterWithEmail ¶
func OnRegisterWithEmail(repository Repository, db *sql.DB) commandbus.CommandHandler
OnRegisterWithEmail creates command handler
func OnRegisterWithFacebook ¶
func OnRegisterWithFacebook(repository Repository, db *sql.DB) commandbus.CommandHandler
OnRegisterWithFacebook creates command handler
func OnRegisterWithGoogle ¶
func OnRegisterWithGoogle(repository Repository, db *sql.DB) commandbus.CommandHandler
OnRegisterWithGoogle creates command handler
func OnRequestAccessToken ¶
func OnRequestAccessToken(repository Repository, db *sql.DB) commandbus.CommandHandler
OnRequestAccessToken creates command handler
Types ¶
type AccessTokenWasRequested ¶
type AccessTokenWasRequested struct { ID uuid.UUID `json:"id"` Email EmailAddress `json:"email"` }
AccessTokenWasRequested event
func (AccessTokenWasRequested) GetType ¶
func (e AccessTokenWasRequested) GetType() string
GetType returns event type
type ChangeEmailAddress ¶
type ChangeEmailAddress struct { ID uuid.UUID `json:"id"` Email EmailAddress `json:"email"` }
ChangeEmailAddress command
func (ChangeEmailAddress) GetName ¶
func (c ChangeEmailAddress) GetName() string
GetName returns command name
type ConnectedWithFacebook ¶
type ConnectedWithFacebook struct { ID uuid.UUID `json:"id"` FacebookID string `json:"facebookId"` }
ConnectedWithFacebook event
func (ConnectedWithFacebook) GetType ¶
func (e ConnectedWithFacebook) GetType() string
GetType returns event type
type ConnectedWithGoogle ¶
ConnectedWithGoogle event
func (ConnectedWithGoogle) GetType ¶
func (e ConnectedWithGoogle) GetType() string
GetType returns event type
type EmailAddress ¶
type EmailAddress string
EmailAddress is an email address value object
func (EmailAddress) IsValid ¶
func (e EmailAddress) IsValid() error
IsValid returns error if value object is not valid
func (EmailAddress) MarshalJSON ¶
func (e EmailAddress) MarshalJSON() ([]byte, error)
MarshalJSON implements Marshal interface
func (*EmailAddress) UnmarshalJSON ¶
func (e *EmailAddress) UnmarshalJSON(b []byte) error
UnmarshalJSON implements Unmarshal interface
type EmailAddressWasChanged ¶
type EmailAddressWasChanged struct { ID uuid.UUID `json:"id"` Email EmailAddress `json:"email"` }
EmailAddressWasChanged event
func (EmailAddressWasChanged) GetType ¶
func (e EmailAddressWasChanged) GetType() string
GetType returns event type
type RegisterWithEmail ¶
type RegisterWithEmail struct {
Email EmailAddress `json:"email"`
}
RegisterWithEmail command
func (RegisterWithEmail) GetName ¶
func (c RegisterWithEmail) GetName() string
GetName returns command name
type RegisterWithFacebook ¶
type RegisterWithFacebook struct { Email EmailAddress `json:"email"` FacebookID string `json:"facebookId"` }
RegisterWithFacebook command
func (RegisterWithFacebook) GetName ¶
func (c RegisterWithFacebook) GetName() string
GetName returns command name
type RegisterWithGoogle ¶
type RegisterWithGoogle struct { Email EmailAddress `json:"email"` GoogleID string `json:"googleId"` }
RegisterWithGoogle command
func (RegisterWithGoogle) GetName ¶
func (c RegisterWithGoogle) GetName() string
GetName returns command name
type Repository ¶
Repository allows to get/save events from/to event store
type RequestAccessToken ¶
RequestAccessToken command
func (RequestAccessToken) GetName ¶
func (c RequestAccessToken) GetName() string
GetName returns command name
type User ¶
type User struct {
// contains filtered or unexported fields
}
User aggregate root
func FromHistory ¶
FromHistory loads current aggregate root state by applying all events in order
func (*User) ChangeEmailAddress ¶
func (u *User) ChangeEmailAddress(email EmailAddress) error
ChangeEmailAddress alters current user state and append changes to aggregate root
func (*User) ConnectWithFacebook ¶
ConnectWithFacebook alters current user state and append changes to aggregate root
func (*User) ConnectWithGoogle ¶
ConnectWithGoogle alters current user state and append changes to aggregate root
func (*User) RegisterWithEmail ¶
func (u *User) RegisterWithEmail(id uuid.UUID, email EmailAddress) error
RegisterWithEmail alters current user state and append changes to aggregate root
func (*User) RegisterWithFacebook ¶
RegisterWithFacebook alters current user state and append changes to aggregate root
func (*User) RegisterWithGoogle ¶
RegisterWithGoogle alters current user state and append changes to aggregate root
func (*User) RequestAccessToken ¶
RequestAccessToken dispatches AccessTokenWasRequested event
type WasRegisteredWithEmail ¶
type WasRegisteredWithEmail struct { ID uuid.UUID `json:"id"` Email EmailAddress `json:"email"` }
WasRegisteredWithEmail event
func (WasRegisteredWithEmail) GetType ¶
func (e WasRegisteredWithEmail) GetType() string
GetType returns event type
type WasRegisteredWithFacebook ¶
type WasRegisteredWithFacebook struct { ID uuid.UUID `json:"id"` Email EmailAddress `json:"email"` FacebookID string `json:"facebookId"` }
WasRegisteredWithFacebook event
func (WasRegisteredWithFacebook) GetType ¶
func (e WasRegisteredWithFacebook) GetType() string
GetType returns event type
type WasRegisteredWithGoogle ¶
type WasRegisteredWithGoogle struct { ID uuid.UUID `json:"id"` Email EmailAddress `json:"email"` GoogleID string `json:"googleId"` }
WasRegisteredWithGoogle event
func (WasRegisteredWithGoogle) GetType ¶
func (e WasRegisteredWithGoogle) GetType() string
GetType returns event type