user

package
v0.0.0-...-c2300e3 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 7 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. But at some point you will want auditing or something that isn't specific to the data/store layer.

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 (
	StatusCreated = Status{"CREATED"}
	StatusActive  = Status{"ACTIVE"}
	StatusDeleted = Status{"DELETED"}
)

Set of possible status for a user.

View Source
var (
	ErrNotFound              = errors.New("user not found")
	ErrUniquePhone           = errors.New("phone is not unique")
	ErrAuthenticationFailure = errors.New("authentication failed")
	ErrInvalidUserStatus     = errors.New("invalid user status")
)

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 *logger.Logger, store Storer) *Core

NewCore constructs a core for user api access.

func (*Core) Authenticate

func (c *Core) Authenticate(ctx context.Context, phone, password string) (User, error)

Authenticate finds a user by their phone 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, core NewUser) (User, error)

Create a new user to the system.

func (*Core) QueryByID

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

QueryByID finds the user by the specified ID.

func (*Core) QueryByPhone

func (c *Core) QueryByPhone(ctx context.Context, phone string) (User, error)

QueryByPhone finds the user by a specified user phone.

func (*Core) Update

func (c *Core) Update(ctx context.Context, o User, n UpdateUser) (User, error)

Update modifies information about a user.

type NewUser

type NewUser struct {
	FirstName string
	LastName  string
	Phone     string
	Password  string
	Status    Status
	Roles     []Role
}

NewUser contains information needed to create a new user.

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 Status

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

Status represents a user status in the system.

func MustParseStatus

func MustParseStatus(value string) Status

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

func ParseStatus

func ParseStatus(value string) (Status, error)

ParseStatus parses the string value and returns a status if one exists.

func (*Status) Equal

func (r *Status) Equal(r2 Status) bool

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

func (*Status) MarshalText

func (r *Status) MarshalText() ([]byte, error)

MarshalText implement the marshal interface for JSON conversions.

func (*Status) Name

func (r *Status) Name() string

Name returns the name of the status.

func (*Status) UnmarshalText

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

UnmarshalText implement the unmarshal interface for JSON conversions.

type Storer

type Storer interface {
	Create(ctx context.Context, core User) error
	Update(ctx context.Context, core User) error
	QueryByID(ctx context.Context, id uuid.UUID) (User, error)
	QueryByIDs(ctx context.Context, ids []uuid.UUID) ([]User, error)
	QueryByPhone(ctx context.Context, phone string) (User, error)
}

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

type UpdateUser

type UpdateUser struct {
	FirstName *string
	LastName  *string
	Roles     []Role
	Password  *string
	Status    *Status
}

UpdateUser contains information needed to update a user.

type User

type User struct {
	ID           uuid.UUID
	FirstName    string
	LastName     string
	Phone        string
	PasswordHash []byte
	Roles        []Role
	Status       Status
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

User represents information about an individual user.

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