userbus

package
v0.0.0-...-8ad27d5 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package userbus provides business access to user domain.

Index

Constants

View Source
const (
	OrderByID      = "user_id"
	OrderByName    = "name"
	OrderByEmail   = "email"
	OrderByRoles   = "roles"
	OrderByEnabled = "enabled"
)

Set of fields that the results can be ordered by.

View Source
const (
	ActionUpdated = "updated"
)

Set of delegate actions.

View Source
const DomainName = "user"

DomainName represents the name of this domain.

Variables

View Source
var (
	ErrNotFound              = errors.New("user not found")
	ErrUniqueEmail           = errors.New("email is not unique")
	ErrAuthenticationFailure = errors.New("authentication failed")
)

Set of error variables for CRUD operations.

View Source
var DefaultOrderBy = order.NewBy(OrderByID, order.ASC)

DefaultOrderBy represents the default way we sort.

View Source
var Roles = roleSet{
	Admin: newRole("ADMIN"),
	User:  newRole("USER"),
}

Roles represents the set of roles that can be used.

Functions

func ActionUpdatedData

func ActionUpdatedData(uu UpdateUser, userID uuid.UUID) delegate.Data

ActionUpdatedData constructs the data for the updated action.

func ParseRolesToString

func ParseRolesToString(usrRoles []Role) []string

ParseRolesToString takes a collection of user roles and converts them to a slice of string.

Types

type ActionUpdatedParms

type ActionUpdatedParms struct {
	UserID uuid.UUID
	UpdateUser
}

ActionUpdatedParms represents the parameters for the updated action.

func (*ActionUpdatedParms) Marshal

func (au *ActionUpdatedParms) Marshal() ([]byte, error)

Marshal returns the event parameters encoded as JSON.

func (*ActionUpdatedParms) String

func (au *ActionUpdatedParms) String() string

String returns a string representation of the action parameters.

type Business

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

Business manages the set of APIs for user access.

func NewBusiness

func NewBusiness(log *logger.Logger, delegate *delegate.Delegate, storer Storer) *Business

NewBusiness constructs a user business API for use.

func (*Business) Authenticate

func (b *Business) Authenticate(ctx context.Context, email mail.Address, password string) (User, error)

Authenticate finds a user by their email and verifies their passworb. On success it returns a Claims User representing this user. The claims can be used to generate a token for future authentication.

func (*Business) Count

func (b *Business) Count(ctx context.Context, filter QueryFilter) (int, error)

Count returns the total number of users.

func (*Business) Create

func (b *Business) Create(ctx context.Context, nu NewUser) (User, error)

Create adds a new user to the system.

func (*Business) Delete

func (b *Business) Delete(ctx context.Context, usr User) error

Delete removes the specified user.

func (*Business) NewWithTx

func (b *Business) NewWithTx(tx sqldb.CommitRollbacker) (*Business, error)

NewWithTx constructs a new business value that will use the specified transaction in any store related calls.

func (*Business) Query

func (b *Business) Query(ctx context.Context, filter QueryFilter, orderBy order.By, page page.Page) ([]User, error)

Query retrieves a list of existing users.

func (*Business) QueryByEmail

func (b *Business) QueryByEmail(ctx context.Context, email mail.Address) (User, error)

QueryByEmail finds the user by a specified user email.

func (*Business) QueryByID

func (b *Business) QueryByID(ctx context.Context, userID uuid.UUID) (User, error)

QueryByID finds the user by the specified Ib.

func (*Business) Update

func (b *Business) Update(ctx context.Context, usr User, uu UpdateUser) (User, error)

Update modifies information about a user.

type Name

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

Name represents a name in the system.

func MustParseName

func MustParseName(value string) Name

MustParseName parses the string value and returns a name if the value complies with the rules for a name. If an error occurs the function panics.

func ParseName

func ParseName(value string) (Name, error)

ParseName parses the string value and returns a name if the value complies with the rules for a name.

func (Name) Equal

func (n Name) Equal(n2 Name) bool

Equal provides support for the go-cmp package and testing.

func (Name) String

func (n Name) String() string

String returns the value of the name.

type NewUser

type NewUser struct {
	Name       Name
	Email      mail.Address
	Roles      []Role
	Department string
	Password   string
}

NewUser contains information needed to create a new user.

func TestNewUsers

func TestNewUsers(n int, role Role) []NewUser

TestNewUsers is a helper method for testing.

type QueryFilter

type QueryFilter struct {
	ID               *uuid.UUID
	Name             *Name
	Email            *mail.Address
	StartCreatedDate *time.Time
	EndCreatedDate   *time.Time
}

QueryFilter holds the available fields a query can be filtered on. We are using pointer semantics because the With API mutates the value.

type Role

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

Role represents a role in the system.

func MustParseRole

func MustParseRole(value string) Role

MustParseRole parses the string value and returns a role if one exists. If an error occurs the function panics.

func ParseRole

func ParseRole(value string) (Role, error)

ParseRole parses the string value and returns a role if one exists.

func ParseRoles

func ParseRoles(roles []string) ([]Role, error)

ParseRoles takes a collection of strings and converts them to a slice of roles.

func (Role) Equal

func (r Role) Equal(r2 Role) bool

Equal provides support for the go-cmp package and testing.

func (Role) String

func (r Role) String() string

String returns the name of the role.

type Storer

type Storer interface {
	NewWithTx(tx sqldb.CommitRollbacker) (Storer, error)
	Create(ctx context.Context, usr User) error
	Update(ctx context.Context, usr User) error
	Delete(ctx context.Context, usr User) error
	Query(ctx context.Context, filter QueryFilter, orderBy order.By, page page.Page) ([]User, error)
	Count(ctx context.Context, filter QueryFilter) (int, error)
	QueryByID(ctx context.Context, userID uuid.UUID) (User, error)
	QueryByEmail(ctx context.Context, email mail.Address) (User, error)
}

Storer interface declares the behavior this package needs to perists and retrieve data.

type UpdateUser

type UpdateUser struct {
	Name       *Name
	Email      *mail.Address
	Roles      []Role
	Department *string
	Password   *string
	Enabled    *bool
}

UpdateUser contains information needed to update a user.

type User

type User struct {
	ID           uuid.UUID
	Name         Name
	Email        mail.Address
	Roles        []Role
	PasswordHash []byte
	Department   string
	Enabled      bool
	DateCreated  time.Time
	DateUpdated  time.Time
}

User represents information about an individual user.

func TestSeedUsers

func TestSeedUsers(ctx context.Context, n int, role Role, api *Business) ([]User, error)

TestSeedUsers is a helper method for testing.

Directories

Path Synopsis
stores
usercache
Package usercache contains user related CRUD functionality with caching.
Package usercache contains user related CRUD functionality with caching.
userdb
Package userdb contains user related CRUD functionality.
Package userdb contains user related CRUD functionality.

Jump to

Keyboard shortcuts

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