Documentation ¶
Overview ¶
Package user holds user domain logic
Index ¶
- Constants
- Variables
- func NewCommandFromPayload(contract string, payload []byte) (domain.Command, error)
- func OnChangeEmailAddress(repository Repository, userRepository persistence.UserRepository) commandbus.CommandHandler
- func OnRegisterWithEmail(repository Repository, userRepository persistence.UserRepository) commandbus.CommandHandler
- func OnRegisterWithFacebook(repository Repository, userRepository persistence.UserRepository) commandbus.CommandHandler
- func OnRegisterWithGoogle(repository Repository, userRepository persistence.UserRepository) commandbus.CommandHandler
- func OnRequestAccessToken(repository Repository) 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(ctx context.Context, email EmailAddress) error
- func (u User) Changes() []*domain.Event
- func (u *User) ConnectWithFacebook(ctx context.Context, facebookID, accessToken, redirectPath string) error
- func (u *User) ConnectWithGoogle(ctx context.Context, googleID, accessToken, redirectPath string) error
- func (u User) ID() uuid.UUID
- func (u *User) RegisterWithEmail(ctx context.Context, id uuid.UUID, email EmailAddress) error
- func (u *User) RegisterWithFacebook(ctx context.Context, id uuid.UUID, email EmailAddress, ...) error
- func (u *User) RegisterWithGoogle(ctx context.Context, id uuid.UUID, email EmailAddress, ...) error
- func (u *User) RequestAccessToken(ctx context.Context, redirectPath string) error
- func (u User) Version() int
- type WasRegisteredWithEmail
- func (e *WasRegisteredWithEmail) GetEmail() string
- func (e *WasRegisteredWithEmail) GetFacebookID() string
- func (e *WasRegisteredWithEmail) GetGoogleID() string
- func (e *WasRegisteredWithEmail) GetID() string
- func (e *WasRegisteredWithEmail) GetRole() access.Role
- func (e WasRegisteredWithEmail) GetType() string
- type WasRegisteredWithFacebook
- func (e *WasRegisteredWithFacebook) GetEmail() string
- func (e *WasRegisteredWithFacebook) GetFacebookID() string
- func (e *WasRegisteredWithFacebook) GetGoogleID() string
- func (e *WasRegisteredWithFacebook) GetID() string
- func (e *WasRegisteredWithFacebook) GetRole() access.Role
- func (e WasRegisteredWithFacebook) GetType() string
- type WasRegisteredWithGoogle
- func (e *WasRegisteredWithGoogle) GetEmail() string
- func (e *WasRegisteredWithGoogle) GetFacebookID() string
- func (e *WasRegisteredWithGoogle) GetGoogleID() string
- func (e *WasRegisteredWithGoogle) GetID() string
- func (e *WasRegisteredWithGoogle) GetRole() access.Role
- func (e WasRegisteredWithGoogle) GetType() string
Constants ¶
const ( // ChangeUserEmailAddress command bus contract ChangeUserEmailAddress = "user-change-email-address" // RequestUserAccessToken command bus contract RequestUserAccessToken = "user-request-access-token" // RegisterUserWithEmail command bus contract RegisterUserWithEmail = "user-register-with-email" // RegisterUserWithFacebook command bus contract RegisterUserWithFacebook = "user-register-with-facebook" // RegisterUserWithGoogle command bus contract RegisterUserWithGoogle = "user-register-with-google" )
Variables ¶
var ( RegisterWithEmailName = (RegisterWithEmail{}).GetName() RequestAccessTokenName = (RequestAccessToken{}).GetName() RegisterWithGoogleName = (RegisterWithGoogle{}).GetName() RegisterWithFacebookName = (RegisterWithFacebook{}).GetName() ChangeEmailAddressName = (ChangeEmailAddress{}).GetName() )
var ( AccessTokenWasRequestedType = (AccessTokenWasRequested{}).GetType() EmailAddressWasChangedType = (EmailAddressWasChanged{}).GetType() WasRegisteredWithEmailType = (WasRegisteredWithEmail{}).GetType() WasRegisteredWithFacebookType = (WasRegisteredWithFacebook{}).GetType() ConnectedWithFacebookType = (ConnectedWithFacebook{}).GetType() WasRegisteredWithGoogleType = (WasRegisteredWithGoogle{}).GetType() ConnectedWithGoogleType = (ConnectedWithGoogle{}).GetType() )
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, userRepository persistence.UserRepository) commandbus.CommandHandler
OnChangeEmailAddress creates command handler
func OnRegisterWithEmail ¶
func OnRegisterWithEmail(repository Repository, userRepository persistence.UserRepository) commandbus.CommandHandler
OnRegisterWithEmail creates command handler
func OnRegisterWithFacebook ¶
func OnRegisterWithFacebook(repository Repository, userRepository persistence.UserRepository) commandbus.CommandHandler
OnRegisterWithFacebook creates command handler
func OnRegisterWithGoogle ¶
func OnRegisterWithGoogle(repository Repository, userRepository persistence.UserRepository) commandbus.CommandHandler
OnRegisterWithGoogle creates command handler
func OnRequestAccessToken ¶
func OnRequestAccessToken(repository Repository) commandbus.CommandHandler
OnRequestAccessToken creates command handler
Types ¶
type AccessTokenWasRequested ¶
type AccessTokenWasRequested struct { ID uuid.UUID `json:"id" bson:"id"` Email EmailAddress `json:"email" bson:"email"` RedirectPath string `json:"redirect_path,omitempty" bson:"redirect_path,omitempty"` }
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" bson:"id"` FacebookID string `json:"facebook_id" bson:"facebook_id"` AccessToken string `json:"access_token" bson:"access_token"` RedirectPath string `json:"redirect_path,omitempty" bson:"redirect_path,omitempty"` }
ConnectedWithFacebook event
func (ConnectedWithFacebook) GetType ¶
func (e ConnectedWithFacebook) GetType() string
GetType returns event type
type ConnectedWithGoogle ¶
type ConnectedWithGoogle struct { ID uuid.UUID `json:"id" bson:"id"` GoogleID string `json:"google_id" bson:"google_id"` AccessToken string `json:"access_token" bson:"access_token"` RedirectPath string `json:"redirect_path,omitempty" bson:"redirect_path,omitempty"` }
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) String ¶
func (e EmailAddress) String() string
func (*EmailAddress) UnmarshalJSON ¶
func (e *EmailAddress) UnmarshalJSON(b []byte) error
UnmarshalJSON implements Unmarshal interface
type EmailAddressWasChanged ¶
type EmailAddressWasChanged struct { ID uuid.UUID `json:"id" bson:"id"` Email EmailAddress `json:"email" bson:"email"` }
EmailAddressWasChanged event
func (EmailAddressWasChanged) GetType ¶
func (e EmailAddressWasChanged) GetType() string
GetType returns event type
type RegisterWithEmail ¶
type RegisterWithEmail struct { Email EmailAddress `json:"email"` RedirectPath string `json:"redirect_path,omitempty"` }
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:"facebook_id"` AccessToken string `json:"access_token"` RedirectPath string `json:"redirect_path,omitempty"` }
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:"google_id"` AccessToken string `json:"access_token"` RedirectPath string `json:"redirect_path,omitempty"` }
RegisterWithGoogle command
func (RegisterWithGoogle) GetName ¶
func (c RegisterWithGoogle) GetName() string
GetName returns command name
type Repository ¶
type Repository interface { Save(ctx context.Context, u User) error Get(ctx context.Context, id uuid.UUID) (User, error) }
Repository allows to get/save events from/to event store
type RequestAccessToken ¶
type RequestAccessToken struct { ID uuid.UUID `json:"id"` RedirectPath string `json:"redirect_path,omitempty"` }
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(ctx context.Context, email EmailAddress) error
ChangeEmailAddress alters current user state and append changes to aggregate root
func (*User) ConnectWithFacebook ¶
func (u *User) ConnectWithFacebook(ctx context.Context, facebookID, accessToken, redirectPath string) error
ConnectWithFacebook alters current user state and append changes to aggregate root
func (*User) ConnectWithGoogle ¶
func (u *User) ConnectWithGoogle(ctx context.Context, googleID, accessToken, redirectPath string) error
ConnectWithGoogle alters current user state and append changes to aggregate root
func (*User) RegisterWithEmail ¶
RegisterWithEmail alters current user state and append changes to aggregate root
func (*User) RegisterWithFacebook ¶
func (u *User) RegisterWithFacebook(ctx context.Context, id uuid.UUID, email EmailAddress, facebookID, accessToken, redirectPath string) error
RegisterWithFacebook alters current user state and append changes to aggregate root
func (*User) RegisterWithGoogle ¶
func (u *User) RegisterWithGoogle(ctx context.Context, id uuid.UUID, email EmailAddress, googleID, accessToken, redirectPath string) error
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" bson:"id"` Email EmailAddress `json:"email" bson:"email"` RedirectPath string `json:"redirect_path,omitempty" bson:"redirect_path,omitempty"` }
WasRegisteredWithEmail event
func (*WasRegisteredWithEmail) GetEmail ¶
func (e *WasRegisteredWithEmail) GetEmail() string
GetEmail the email
func (*WasRegisteredWithEmail) GetFacebookID ¶
func (e *WasRegisteredWithEmail) GetFacebookID() string
GetFacebookID facebook id
func (*WasRegisteredWithEmail) GetGoogleID ¶
func (e *WasRegisteredWithEmail) GetGoogleID() string
GetGoogleID google id
func (*WasRegisteredWithEmail) GetRole ¶
func (e *WasRegisteredWithEmail) GetRole() access.Role
GetRole
func (WasRegisteredWithEmail) GetType ¶
func (e WasRegisteredWithEmail) GetType() string
GetType returns event type
type WasRegisteredWithFacebook ¶
type WasRegisteredWithFacebook struct { ID uuid.UUID `json:"id" bson:"id"` Email EmailAddress `json:"email" bson:"email"` FacebookID string `json:"facebook_id" bson:"facebook_id"` AccessToken string `json:"access_token" bson:"access_token"` RedirectPath string `json:"redirect_path,omitempty" bson:"redirect_path,omitempty"` }
WasRegisteredWithFacebook event
func (*WasRegisteredWithFacebook) GetEmail ¶
func (e *WasRegisteredWithFacebook) GetEmail() string
GetEmail the email
func (*WasRegisteredWithFacebook) GetFacebookID ¶
func (e *WasRegisteredWithFacebook) GetFacebookID() string
GetFacebookID facebook id
func (*WasRegisteredWithFacebook) GetGoogleID ¶
func (e *WasRegisteredWithFacebook) GetGoogleID() string
GetGoogleID google id
func (*WasRegisteredWithFacebook) GetID ¶
func (e *WasRegisteredWithFacebook) GetID() string
GetID the id
func (*WasRegisteredWithFacebook) GetRole ¶
func (e *WasRegisteredWithFacebook) GetRole() access.Role
GetRole
func (WasRegisteredWithFacebook) GetType ¶
func (e WasRegisteredWithFacebook) GetType() string
GetType returns event type
type WasRegisteredWithGoogle ¶
type WasRegisteredWithGoogle struct { ID uuid.UUID `json:"id" bson:"id"` Email EmailAddress `json:"email" bson:"email"` GoogleID string `json:"google_id" bson:"google_id"` AccessToken string `json:"access_token" bson:"access_token"` RedirectPath string `json:"redirect_path,omitempty" bson:"redirect_path,omitempty"` }
WasRegisteredWithGoogle event
func (*WasRegisteredWithGoogle) GetEmail ¶
func (e *WasRegisteredWithGoogle) GetEmail() string
GetEmail the email
func (*WasRegisteredWithGoogle) GetFacebookID ¶
func (e *WasRegisteredWithGoogle) GetFacebookID() string
GetFacebookID facebook id
func (*WasRegisteredWithGoogle) GetGoogleID ¶
func (e *WasRegisteredWithGoogle) GetGoogleID() string
GetGoogleID google id
func (*WasRegisteredWithGoogle) GetID ¶
func (e *WasRegisteredWithGoogle) GetID() string
GetID the id
func (*WasRegisteredWithGoogle) GetRole ¶
func (e *WasRegisteredWithGoogle) GetRole() access.Role
GetRole
func (WasRegisteredWithGoogle) GetType ¶
func (e WasRegisteredWithGoogle) GetType() string
GetType returns event type