Documentation
¶
Overview ¶
Package userbus provides business access to user domain.
Index ¶
- Constants
- Variables
- func ActionDeletedData(userID uuid.UUID) delegate.Data
- type ActionDeletedParms
- type Business
- func (b *Business) Authenticate(ctx context.Context, email mail.Address, password string) (User, error)
- func (b *Business) Count(ctx context.Context, filter QueryFilter) (int, error)
- func (b *Business) Create(ctx context.Context, actorID uuid.UUID, nu NewUser) (User, error)
- func (b *Business) Delete(ctx context.Context, actorID uuid.UUID, usr User) error
- func (b *Business) NewWithTx(tx sqldb.CommitRollbacker) (ExtBusiness, error)
- func (b *Business) Query(ctx context.Context, filter QueryFilter, orderBy order.By, page page.Page) ([]User, error)
- func (b *Business) QueryByEmail(ctx context.Context, email mail.Address) (User, error)
- func (b *Business) QueryByID(ctx context.Context, userID uuid.UUID) (User, error)
- func (b *Business) Update(ctx context.Context, actorID uuid.UUID, usr User, uu UpdateUser) (User, error)
- type ExtBusiness
- type Extension
- type NewUser
- type QueryFilter
- type Storer
- type UpdateUser
- type User
Constants ¶
const ( OrderByID = "a" OrderByName = "b" OrderByEmail = "c" OrderByRoles = "d" OrderByEnabled = "e" )
Set of fields that the results can be ordered by.
const (
ActionDeleted = "deleted"
)
Set of delegate actions.
const DomainName = "user"
DomainName represents the name of this domain.
Variables ¶
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.
DefaultOrderBy represents the default way we sort.
Functions ¶
Types ¶
type ActionDeletedParms ¶
ActionDeletedParms represents the parameters for the deleted action.
func (*ActionDeletedParms) Marshal ¶
func (act *ActionDeletedParms) Marshal() ([]byte, error)
Marshal returns the event parameters encoded as JSON.
func (*ActionDeletedParms) String ¶
func (act *ActionDeletedParms) 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 (*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 password. On success it returns a Claims User representing this user. The claims can be used to generate a token for future authentication.
func (*Business) NewWithTx ¶
func (b *Business) NewWithTx(tx sqldb.CommitRollbacker) (ExtBusiness, 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 ¶
QueryByEmail finds the user by a specified user email.
type ExtBusiness ¶
type ExtBusiness interface {
NewWithTx(tx sqldb.CommitRollbacker) (ExtBusiness, error)
Create(ctx context.Context, actorID uuid.UUID, nu NewUser) (User, error)
Update(ctx context.Context, actorID uuid.UUID, usr User, uu UpdateUser) (User, error)
Delete(ctx context.Context, actorID uuid.UUID, 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)
Authenticate(ctx context.Context, email mail.Address, password string) (User, error)
}
ExtBusiness interface provides support for extensions that wrap extra functionality around the core busines logic.
func NewBusiness ¶
func NewBusiness(log *logger.Logger, delegate *delegate.Delegate, storer Storer, extensions ...Extension) ExtBusiness
NewBusiness constructs a user business API for use.
type Extension ¶
type Extension func(ExtBusiness) ExtBusiness
Extension is a function that wraps a new layer of business logic around the existing business logic.
type NewUser ¶
type NewUser struct {
Name name.Name
Email mail.Address
Roles []role.Role
Department name.Null
Password string
}
NewUser contains information needed to create a new user.
type QueryFilter ¶
type QueryFilter struct {
ID *uuid.UUID
Name *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 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 persist and retrieve data.
type UpdateUser ¶
type UpdateUser struct {
Name *name.Name
Email *mail.Address
Roles []role.Role
Department *name.Null
Password *string
Enabled *bool
}
UpdateUser contains information needed to update a user.
type User ¶
type User struct {
ID uuid.UUID
Name name.Name
Email mail.Address
Roles []role.Role
PasswordHash []byte
Department name.Null
Enabled bool
DateCreated time.Time
DateUpdated time.Time
}
User represents information about an individual user.
func TestSeedUsers ¶
TestSeedUsers is a helper method for testing.
Directories
¶
| Path | Synopsis |
|---|---|
|
extensions
|
|
|
useraudit
Package useraudit provides an extension for userbus that adds auditing functionality.
|
Package useraudit provides an extension for userbus that adds auditing functionality. |
|
userotel
Package userotel provides an extension for userbus that adds otel tracking.
|
Package userotel provides an extension for userbus that adds otel tracking. |
|
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. |