Documentation ¶
Overview ¶
Package user provides an example of a core business API. Right now these calls are just wrapping the data/data layer. But at some point you will want auditing or something that isn't specific to the data/store layer.
Index ¶
- Constants
- Variables
- func ActionUpdatedData(uu UpdateUser, userID uuid.UUID) delegate.Data
- type ActionUpdatedParms
- type Core
- func (c *Core) Authenticate(ctx context.Context, email mail.Address, password string) (User, error)
- func (c *Core) Count(ctx context.Context, filter QueryFilter) (int, error)
- func (c *Core) Create(ctx context.Context, nu NewUser) (User, error)
- func (c *Core) Delete(ctx context.Context, usr User) error
- func (c *Core) ExecuteUnderTransaction(tx transaction.Transaction) (*Core, error)
- func (c *Core) Query(ctx context.Context, filter QueryFilter, orderBy order.By, pageNumber int, ...) ([]User, error)
- func (c *Core) QueryByEmail(ctx context.Context, email mail.Address) (User, error)
- func (c *Core) QueryByID(ctx context.Context, userID uuid.UUID) (User, error)
- func (c *Core) QueryByIDs(ctx context.Context, userIDs []uuid.UUID) ([]User, error)
- func (c *Core) Update(ctx context.Context, usr User, uu UpdateUser) (User, error)
- type NewUser
- type QueryFilter
- func (qf *QueryFilter) Validate() error
- func (qf *QueryFilter) WithEmail(email mail.Address)
- func (qf *QueryFilter) WithEndCreatedDate(endDate time.Time)
- func (qf *QueryFilter) WithName(name string)
- func (qf *QueryFilter) WithStartDateCreated(startDate time.Time)
- func (qf *QueryFilter) WithUserID(userID uuid.UUID)
- type Role
- type Storer
- type UpdateUser
- type User
Constants ¶
const ( OrderByID = "user_id" OrderByName = "name" OrderByEmail = "email" OrderByRoles = "roles" OrderByEnabled = "enabled" )
Set of fields that the results can be ordered by.
const (
ActionUpdated = "updated"
)
Set of delegate actions.
const Domain = "user"
Domain represents the name of this domain.
Variables ¶
var ( RoleAdmin = Role{"ADMIN"} RoleUser = Role{"USER"} )
Set of possible roles for a user.
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 ¶
func ActionUpdatedData ¶
func ActionUpdatedData(uu UpdateUser, userID uuid.UUID) delegate.Data
ActionUpdatedData constructs the data for the updated action.
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 Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core manages the set of APIs for user access.
func (*Core) Authenticate ¶
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 (*Core) ExecuteUnderTransaction ¶
func (c *Core) ExecuteUnderTransaction(tx transaction.Transaction) (*Core, error)
ExecuteUnderTransaction constructs a new Core value that will use the specified transaction in any store related calls.
func (*Core) Query ¶
func (c *Core) Query(ctx context.Context, filter QueryFilter, orderBy order.By, pageNumber int, rowsPerPage int) ([]User, error)
Query retrieves a list of existing users.
func (*Core) QueryByEmail ¶
QueryByEmail finds the user by a specified user email.
func (*Core) QueryByIDs ¶
QueryByIDs finds the users by a specified User IDs.
type NewUser ¶
type NewUser struct { Name string Email mail.Address Roles []Role Department string Password string PasswordConfirm string }
NewUser contains information needed to create a new user.
func TestGenerateNewUsers ¶
TestGenerateNewUsers is a helper method for testing.
type QueryFilter ¶
type QueryFilter struct { ID *uuid.UUID Name *string `validate:"omitempty,min=3"` 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.
func (*QueryFilter) Validate ¶
func (qf *QueryFilter) Validate() error
Validate can perform a check of the data against the validate tags.
func (*QueryFilter) WithEmail ¶
func (qf *QueryFilter) WithEmail(email mail.Address)
WithEmail sets the Email field of the QueryFilter value.
func (*QueryFilter) WithEndCreatedDate ¶
func (qf *QueryFilter) WithEndCreatedDate(endDate time.Time)
WithEndCreatedDate sets the EndCreatedDate field of the QueryFilter value.
func (*QueryFilter) WithName ¶
func (qf *QueryFilter) WithName(name string)
WithName sets the Name field of the QueryFilter value.
func (*QueryFilter) WithStartDateCreated ¶
func (qf *QueryFilter) WithStartDateCreated(startDate time.Time)
WithStartDateCreated sets the StartCreatedDate field of the QueryFilter value.
func (*QueryFilter) WithUserID ¶
func (qf *QueryFilter) WithUserID(userID uuid.UUID)
WithUserID sets the ID field of the QueryFilter value.
type Role ¶
type Role struct {
// contains filtered or unexported fields
}
Role represents a role in the system.
func MustParseRole ¶
MustParseRole parses the string value and returns a role if one exists. If an error occurs the function panics.
func (Role) MarshalText ¶
MarshalText implement the marshal interface for JSON conversions.
func (*Role) UnmarshalText ¶
UnmarshalText implement the unmarshal interface for JSON conversions.
type Storer ¶
type Storer interface { ExecuteUnderTransaction(tx transaction.Transaction) (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, pageNumber int, rowsPerPage int) ([]User, error) Count(ctx context.Context, filter QueryFilter) (int, error) QueryByID(ctx context.Context, userID uuid.UUID) (User, error) QueryByIDs(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 *string Email *mail.Address Roles []Role Department *string Password *string PasswordConfirm *string Enabled *bool }
UpdateUser contains information needed to update a user.
Source Files ¶
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. |