user

package
v0.0.0-...-e400c07 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package user provides an example of a core business API. Right now these calls are just wrapping the data/data layer.

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. These are the names that should be used by the application layer.

Variables

View Source
var (
	RoleAdmin = Role{"ADMIN"}
	RoleUser  = Role{"USER"}
)

Set of possible roles for a user.

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.

Functions

This section is empty.

Types

type Core

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

Core manages the set of APIs for user api access

func NewCore

func NewCore(st Storer, log *logger.Logger) *Core

NewCore constructs a core for user api access.

func (*Core) Authenticate

func (c *Core) 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 (*Core) Create

func (c *Core) Create(ctx context.Context, newUser NewUser) (User, error)

Create adds a new user to the system.

func (*Core) Delete

func (c *Core) Delete(ctx context.Context, usr User) error

Delete removes a specified user.

func (*Core) QueryByEmail

func (c *Core) QueryByEmail(ctx context.Context, email mail.Address) (User, error)

QueryByEmail finds the user by a specified user email.

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.

type QueryFilter

type QueryFilter struct {
	ID               *uuid.UUID    `validate:"omitempty"`
	Name             *string       `validate:"omitempty,min=3"`
	Email            *mail.Address `validate:"omitempty"`
	StartCreatedDate *time.Time    `validate:"omitempty"`
	EndCreatedDate   *time.Time    `validate:"omitempty"`
}

QueryFilter holds the available fields a query can be filtered on.

func (*QueryFilter) Validate

func (qf *QueryFilter) Validate() error

Validate checks the data in the model is considered clean.

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 DateCreated 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 DateCreated 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

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 (Role) Equal

func (r Role) Equal(r2 Role) bool

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

func (Role) MarshalText

func (r Role) MarshalText() ([]byte, error)

MarshalText implement the marshal interface for JSON conversions.

func (Role) Name

func (r Role) Name() string

Name returns the name of the role.

func (*Role) UnmarshalText

func (r *Role) UnmarshalText(data []byte) error

UnmarshalText implement the unmarshal interface for JSON conversions.

type Storer

type Storer interface {
	Create(ctx context.Context, user User) (sql.Result, error)
	Delete(ctx context.Context, user User) error
	QueryByEmail(ctx context.Context, email mail.Address) (User, error)
}

Storer interface declares the core behavior and is required to write and retrieve data.

type UpdateUser

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

type User

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

User represents information about an individual user.

Directories

Path Synopsis
stores

Jump to

Keyboard shortcuts

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