user

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package user holds user domain logic

Package user holds user domain logic

Index

Constants

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

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, 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

type ConnectedWithGoogle struct {
	ID       uuid.UUID `json:"id"`
	GoogleID string    `json:"googleId"`
}

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

type Repository interface {
	Save(ctx context.Context, u User) error
	Get(id uuid.UUID) User
}

Repository allows to get/save events from/to event store

type RequestAccessToken

type RequestAccessToken struct {
	ID uuid.UUID `json:"id"`
}

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(events []domain.Event) User

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(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(facebookID string) error

ConnectWithFacebook alters current user state and append changes to aggregate root

func (*User) ConnectWithGoogle

func (u *User) ConnectWithGoogle(googleID 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(id uuid.UUID, email EmailAddress) error

RegisterWithEmail alters current user state and append changes to aggregate root

func (*User) RegisterWithFacebook

func (u *User) RegisterWithFacebook(id uuid.UUID, email EmailAddress, facebookID string) error

RegisterWithFacebook alters current user state and append changes to aggregate root

func (*User) RegisterWithGoogle

func (u *User) RegisterWithGoogle(id uuid.UUID, email EmailAddress, googleID string) error

RegisterWithGoogle alters current user state and append changes to aggregate root

func (*User) RequestAccessToken

func (u *User) RequestAccessToken() 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"`
	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

Jump to

Keyboard shortcuts

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