go-api-boilerplate: github.com/vardius/go-api-boilerplate/cmd/user/internal/domain/user Index | Files

package user

import "github.com/vardius/go-api-boilerplate/cmd/user/internal/domain/user"

Package user holds user domain logic

Package user holds user domain logic

Index

Package Files

commands.go email_address.go errors.go events.go json.go repository.go user.go

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

func NewCommandFromPayload Uses

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

NewCommandFromPayload builds command by contract from json payload

func OnChangeEmailAddress Uses

func OnChangeEmailAddress(repository Repository, db *sql.DB) commandbus.CommandHandler

OnChangeEmailAddress creates command handler

func OnRegisterWithEmail Uses

func OnRegisterWithEmail(repository Repository, db *sql.DB) commandbus.CommandHandler

OnRegisterWithEmail creates command handler

func OnRegisterWithFacebook Uses

func OnRegisterWithFacebook(repository Repository, db *sql.DB) commandbus.CommandHandler

OnRegisterWithFacebook creates command handler

func OnRegisterWithGoogle Uses

func OnRegisterWithGoogle(repository Repository, db *sql.DB) commandbus.CommandHandler

OnRegisterWithGoogle creates command handler

func OnRequestAccessToken Uses

func OnRequestAccessToken(repository Repository, db *sql.DB) commandbus.CommandHandler

OnRequestAccessToken creates command handler

type AccessTokenWasRequested Uses

type AccessTokenWasRequested struct {
    ID    uuid.UUID    `json:"id"`
    Email EmailAddress `json:"email"`
}

AccessTokenWasRequested event

func (AccessTokenWasRequested) GetType Uses

func (e AccessTokenWasRequested) GetType() string

GetType returns event type

type ChangeEmailAddress Uses

type ChangeEmailAddress struct {
    ID    uuid.UUID    `json:"id"`
    Email EmailAddress `json:"email"`
}

ChangeEmailAddress command

func (ChangeEmailAddress) GetName Uses

func (c ChangeEmailAddress) GetName() string

GetName returns command name

type ConnectedWithFacebook Uses

type ConnectedWithFacebook struct {
    ID         uuid.UUID `json:"id"`
    FacebookID string    `json:"facebookId"`
}

ConnectedWithFacebook event

func (ConnectedWithFacebook) GetType Uses

func (e ConnectedWithFacebook) GetType() string

GetType returns event type

type ConnectedWithGoogle Uses

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

ConnectedWithGoogle event

func (ConnectedWithGoogle) GetType Uses

func (e ConnectedWithGoogle) GetType() string

GetType returns event type

type EmailAddress Uses

type EmailAddress string

EmailAddress is an email address value object

func (EmailAddress) IsValid Uses

func (e EmailAddress) IsValid() error

IsValid returns error if value object is not valid

func (EmailAddress) MarshalJSON Uses

func (e EmailAddress) MarshalJSON() ([]byte, error)

MarshalJSON implements Marshal interface

func (*EmailAddress) UnmarshalJSON Uses

func (e *EmailAddress) UnmarshalJSON(b []byte) error

UnmarshalJSON implements Unmarshal interface

type EmailAddressWasChanged Uses

type EmailAddressWasChanged struct {
    ID    uuid.UUID    `json:"id"`
    Email EmailAddress `json:"email"`
}

EmailAddressWasChanged event

func (EmailAddressWasChanged) GetType Uses

func (e EmailAddressWasChanged) GetType() string

GetType returns event type

type RegisterWithEmail Uses

type RegisterWithEmail struct {
    Email EmailAddress `json:"email"`
}

RegisterWithEmail command

func (RegisterWithEmail) GetName Uses

func (c RegisterWithEmail) GetName() string

GetName returns command name

type RegisterWithFacebook Uses

type RegisterWithFacebook struct {
    Email      EmailAddress `json:"email"`
    FacebookID string       `json:"facebookId"`
}

RegisterWithFacebook command

func (RegisterWithFacebook) GetName Uses

func (c RegisterWithFacebook) GetName() string

GetName returns command name

type RegisterWithGoogle Uses

type RegisterWithGoogle struct {
    Email    EmailAddress `json:"email"`
    GoogleID string       `json:"googleId"`
}

RegisterWithGoogle command

func (RegisterWithGoogle) GetName Uses

func (c RegisterWithGoogle) GetName() string

GetName returns command name

type Repository Uses

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 Uses

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

RequestAccessToken command

func (RequestAccessToken) GetName Uses

func (c RequestAccessToken) GetName() string

GetName returns command name

type User Uses

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

User aggregate root

func FromHistory Uses

func FromHistory(events []domain.Event) User

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

func New Uses

func New() User

New creates an User

func (*User) ChangeEmailAddress Uses

func (u *User) ChangeEmailAddress(email EmailAddress) error

ChangeEmailAddress alters current user state and append changes to aggregate root

func (User) Changes Uses

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

Changes returns all new applied events

func (*User) ConnectWithFacebook Uses

func (u *User) ConnectWithFacebook(facebookID string) error

ConnectWithFacebook alters current user state and append changes to aggregate root

func (*User) ConnectWithGoogle Uses

func (u *User) ConnectWithGoogle(googleID string) error

ConnectWithGoogle alters current user state and append changes to aggregate root

func (User) ID Uses

func (u User) ID() uuid.UUID

ID returns aggregate root id

func (*User) RegisterWithEmail Uses

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

RegisterWithEmail alters current user state and append changes to aggregate root

func (*User) RegisterWithFacebook Uses

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 Uses

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 Uses

func (u *User) RequestAccessToken() error

RequestAccessToken dispatches AccessTokenWasRequested event

func (User) Version Uses

func (u User) Version() int

Version returns current aggregate root version

type WasRegisteredWithEmail Uses

type WasRegisteredWithEmail struct {
    ID    uuid.UUID    `json:"id"`
    Email EmailAddress `json:"email"`
}

WasRegisteredWithEmail event

func (WasRegisteredWithEmail) GetType Uses

func (e WasRegisteredWithEmail) GetType() string

GetType returns event type

type WasRegisteredWithFacebook Uses

type WasRegisteredWithFacebook struct {
    ID         uuid.UUID    `json:"id"`
    Email      EmailAddress `json:"email"`
    FacebookID string       `json:"facebookId"`
}

WasRegisteredWithFacebook event

func (WasRegisteredWithFacebook) GetType Uses

func (e WasRegisteredWithFacebook) GetType() string

GetType returns event type

type WasRegisteredWithGoogle Uses

type WasRegisteredWithGoogle struct {
    ID       uuid.UUID    `json:"id"`
    Email    EmailAddress `json:"email"`
    GoogleID string       `json:"googleId"`
}

WasRegisteredWithGoogle event

func (WasRegisteredWithGoogle) GetType Uses

func (e WasRegisteredWithGoogle) GetType() string

GetType returns event type

Package user imports 13 packages (graph) and is imported by 6 packages. Updated 2020-08-04. Refresh now. Tools for package owners.