user

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Save

func Save(store event.Store, user *User, metadata interface{}) error

Save can be used to dehydrate a User into an event store.

func UserCodec

func UserCodec() *event.Codec

UserCodec is used for un-/marshaling puroposes.

Types

type Created

type Created struct {
	ID         string    `json:"id"`          // The id of the event (useful for deduplication purposes).
	OccurredOn time.Time `json:"occurred-on"` // The point in time when this event occurred.
	User       UserID    `json:"user"`        // The id of the new User entity lifecycle.
}

Created must be the very first event in a User entity lifecycle.

type Metadata

type Metadata struct {
	UserName    string `json:"user-name,omitempty"`
	Causation   string `json:"causation,omitempty"`
	Correlation string `json:"correlation,omitempty"`
}

type NameChanged

type NameChanged struct {
	ID         string    `json:"id"`          // The id of the envent (useful for deduplication purposes).
	OccurredOn time.Time `json:"occurred-on"` // The point in time when this event occurred.
	User       UserID    `json:"user"`        // The id of the User entity lifecycle.
	Name       string    `json:"name"`        // The new name of the User going forward.
}

NameChanged will always be generated when a Users name changes.

type Projection

type Projection struct {
	// contains filtered or unexported fields
}

Projection can answer some questions about the user domain.

func NewProjection

func NewProjection() *Projection

NewProjection creates a new Projection. In a production system this should probably be something persistent.

func (*Projection) IsUserNameInUse

func (p *Projection) IsUserNameInUse(name string) bool

IsUserNameInUse will check if the provided name is currently in use by a user.

func (*Projection) NumberOfNameChangesForUser

func (p *Projection) NumberOfNameChangesForUser(id UserID) int

NumberOfNameChangesForUser will retrieve the number of name changes in history for a given user

func (*Projection) On

func (p *Projection) On(rec event.Record)

On should be called for each event in history.

func (*Projection) TotalNumberOfNameChanges

func (p *Projection) TotalNumberOfNameChanges() int

TotalNumberOfNameChanges will retrieve the total number of name changes in history

func (*Projection) UserName

func (p *Projection) UserName(id UserID) string

UserName will retrieve a users current name.

type User

type User struct {
	ID                    UserID // The id of the User entity.
	Version               uint64 // The current version of the User entity.
	Name                  string // The current name of the User entity.
	*event.ChangeRecorder        // The ChangeRecorder is embeded to track changes as a unit of work.
}

User is an event sourced entity.

func Load

func Load(store event.Store, uID UserID) (*User, error)

Load can be used to rehydrate a User from an event store.

func NewUser

func NewUser() *User

NewUser creates a User entity.

func (*User) Apply

func (u *User) Apply(e event.Event)

Apply should be called to apply a new Event to the User entity model.

func (*User) ChangeName

func (u *User) ChangeName(name string) error

ChangeName is a command that should be called any time this users name should change.

func (*User) Create

func (u *User) Create(id UserID) error

Create is a command that should be called first in the lifecycle of a User entity.

func (*User) Mutate

func (u *User) Mutate(e event.Event)

Mutate should be called for each event in the users history.

type UserID

type UserID string

UserID is used to identify the User entity.

Jump to

Keyboard shortcuts

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