user

package
v0.0.0-...-ac0e98d Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package user provides a core business API.

Index

Constants

This section is empty.

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")
	ErrAuthorizationFailure  = errors.New("authorization failed")
)

Set of error variables for CRUD operations.

Functions

This section is empty.

Types

type Core

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

Core manages the set of APIs for user access.

func NewCore

func NewCore(log *zerolog.Logger, storer Storer) *Core

NewCore constructs a user core API for use.

func (*Core) Authenticate

func (c *Core) Authenticate(email string, password string) (User, error)

func (*Core) Create

func (c *Core) Create(nu NewUser) (User, error)

Create adds a new user to the system.

func (*Core) CreateTx

func (c *Core) CreateTx(nuTx NewUserTx) (User, error)

func (*Core) Delete

func (c *Core) Delete(usr User) error

Delete removes the specified user.

func (*Core) Query

func (c *Core) Query(pageNumber int, rowsPerPage int) ([]User, error)

Query retrieves a list of existing users.

func (*Core) QueryByEmail

func (c *Core) QueryByEmail(email string) (User, error)

QueryByEmail finds the user by a specified user email.

func (*Core) QueryByID

func (c *Core) QueryByID(id uuid.UUID) (User, error)

QueryByID finds the user by the specified ID.

func (*Core) QueryByTopicID

func (c *Core) QueryByTopicID(topicID uuid.UUID) ([]User, error)

func (*Core) Update

func (c *Core) Update(usr User, uu UpdateUser) (User, error)

Update modifies information about a user.

type NewUser

type NewUser struct {
	Email    string
	Roles    []Role
	Password string
}

NewUser contains information needed to create a new user.

type NewUserTx

type NewUserTx struct {
	NewUser
	AfterCreate func(user User) error
}

NewUserTx contains information needed to create a new user in a transaction.

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 {
	WithinTran(fn func(s Storer) error) error
	Create(usr User) error
	Update(usr User) error
	Delete(usr User) error
	Query(pageNumber int, rowsPerPage int) ([]User, error)
	QueryByID(id uuid.UUID) (User, error)
	QueryByEmail(email string) (User, error)
	QueryByTopicID(topicID uuid.UUID) ([]User, error)
}

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

type UpdateUser

type UpdateUser struct {
	Email    *string
	Roles    []Role
	Verified *bool
	Password *string
}

UpdateUser contains information needed to update a user.

type User

type User struct {
	ID             uuid.UUID
	Email          string
	Roles          []Role
	Verified       bool
	HashedPassword []byte
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

User represents information about an individual user.

Directories

Path Synopsis
Package mockusr is a generated GoMock package.
Package mockusr is a generated GoMock package.
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