user

package
v0.0.1-0...-6deec57 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package user holds user domain logic

Index

Constants

View Source
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

View Source
var (
	RegisterWithEmailName    = (RegisterWithEmail{}).GetName()
	RequestAccessTokenName   = (RequestAccessToken{}).GetName()
	RegisterWithGoogleName   = (RegisterWithGoogle{}).GetName()
	RegisterWithFacebookName = (RegisterWithFacebook{}).GetName()
	ChangeEmailAddressName   = (ChangeEmailAddress{}).GetName()
)
View Source
var (
	AccessTokenWasRequestedType   = (AccessTokenWasRequested{}).GetType()
	EmailAddressWasChangedType    = (EmailAddressWasChanged{}).GetType()
	WasRegisteredWithEmailType    = (WasRegisteredWithEmail{}).GetType()
	WasRegisteredWithFacebookType = (WasRegisteredWithFacebook{}).GetType()
	ConnectedWithFacebookType     = (ConnectedWithFacebook{}).GetType()
	WasRegisteredWithGoogleType   = (WasRegisteredWithGoogle{}).GetType()
	ConnectedWithGoogleType       = (ConnectedWithGoogle{}).GetType()
)
View Source
var ErrAlreadyRegistered = fmt.Errorf("user is already registered")

ErrAlreadyRegistered is when user with given email already exist.

View Source
var StreamName = fmt.Sprintf("%T", User{})

StreamName for user domain

Functions

func NewCommandFromPayload

func NewCommandFromPayload(contract string, payload []byte) (domain.Command, error)

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

func FromHistory(ctx context.Context, events []*domain.Event) (User, error)

FromHistory loads current aggregate root state by applying all events in order

func New

func New() User

New creates an User

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) Changes

func (u User) Changes() []*domain.Event

Changes returns all new applied events

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) ID

func (u User) ID() uuid.UUID

ID returns aggregate root id

func (*User) RegisterWithEmail

func (u *User) RegisterWithEmail(ctx context.Context, id uuid.UUID, email EmailAddress) error

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

func (u *User) RequestAccessToken(ctx context.Context, redirectPath string) error

RequestAccessToken dispatches AccessTokenWasRequested event

func (User) Version

func (u User) Version() int

Version returns current aggregate root version

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) GetID

func (e *WasRegisteredWithEmail) GetID() string

GetID the 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL