user

package
v0.0.0-...-2e936b0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

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("not found")
	ErrAuthenticationFailure = errors.New("authentication failure")
	ErrAlreadyExists         = errors.New("already exists")
)

Functions

This section is empty.

Types

type Core

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

func NewCore

func NewCore(userRepo Repo) *Core

func (*Core) Add

func (u *Core) Add(ctx context.Context, nu NewUser, now time.Time) (User, error)

Add user to the app with passed credentials.

func (*Core) Authenticate

func (u *Core) Authenticate(ctx context.Context, name, 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) Count

func (u *Core) Count(ctx context.Context) (int, error)

Count returns total number of users in the app.

func (*Core) GetAll

func (u *Core) GetAll(ctx context.Context) ([]User, error)

GetAll list all app users.

func (*Core) GetByID

func (u *Core) GetByID(ctx context.Context, userID uuid.UUID) (User, error)

GetByID finds user by user id in the app.

func (*Core) GetByIDs

func (u *Core) GetByIDs(ctx context.Context, userIDs []uuid.UUID) ([]User, error)

GetByIDs finds users by user IDs.

func (*Core) GetByUsername

func (u *Core) GetByUsername(ctx context.Context, username string) (User, error)

GetByUsername finds user by username in the app.

type Mock

type Mock struct {
	mock.Mock
}

func NewRepoMock

func NewRepoMock() *Mock

func (*Mock) Add

func (r *Mock) Add(ctx context.Context, nu User) error

func (*Mock) Count

func (r *Mock) Count(ctx context.Context) (int, error)

func (*Mock) GetAll

func (r *Mock) GetAll(ctx context.Context) ([]User, error)

func (*Mock) GetByID

func (r *Mock) GetByID(ctx context.Context, userID uuid.UUID) (User, error)

func (*Mock) GetByIDs

func (r *Mock) GetByIDs(ctx context.Context, userIDs []uuid.UUID) ([]User, error)

func (*Mock) GetByUsername

func (r *Mock) GetByUsername(ctx context.Context, username string) (User, error)

type NewUser

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

NewUser is what we require to add User.

type Repo

type Repo interface {
	Add(ctx context.Context, nu User) error
	Count(ctx context.Context) (int, error)
	GetAll(ctx context.Context) ([]User, error)
	GetByID(ctx context.Context, userID uuid.UUID) (User, error)
	GetByIDs(ctx context.Context, userIDs []uuid.UUID) ([]User, error)
	GetByUsername(ctx context.Context, username string) (User, error)
}

Repo represents user storage interface

type Role

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

Role Represents a user role in the system.

func ParseRole

func ParseRole(name string) (Role, error)

ParseRole get the role name and return it if exist.

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

func (*Role) UnmarshalText

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

type Usecase

type Usecase interface {
	Add(ctx context.Context, nu NewUser, now time.Time) (User, error)
	Count(ctx context.Context) (int, error)
	GetAll(ctx context.Context) ([]User, error)
	GetByID(ctx context.Context, userID uuid.UUID) (User, error)
	GetByIDs(ctx context.Context, userIDs []uuid.UUID) ([]User, error)
	GetByUsername(cxt context.Context, username string) (User, error)
	Authenticate(ctx context.Context, name, password string) (User, error)
}

Usecase represents user use cases.

type UsecaseMock

type UsecaseMock struct {
	mock.Mock
}

func NewUsecaseMock

func NewUsecaseMock() *UsecaseMock

func (*UsecaseMock) Add

func (r *UsecaseMock) Add(ctx context.Context, nu NewUser, now time.Time) (User, error)

func (*UsecaseMock) Authenticate

func (r *UsecaseMock) Authenticate(ctx context.Context, name, password string) (User, error)

func (*UsecaseMock) Count

func (r *UsecaseMock) Count(ctx context.Context) (int, error)

func (*UsecaseMock) GetAll

func (r *UsecaseMock) GetAll(ctx context.Context) ([]User, error)

func (*UsecaseMock) GetByID

func (r *UsecaseMock) GetByID(ctx context.Context, userID uuid.UUID) (User, error)

func (*UsecaseMock) GetByIDs

func (r *UsecaseMock) GetByIDs(ctx context.Context, userIDs []uuid.UUID) ([]User, error)

func (*UsecaseMock) GetByUsername

func (r *UsecaseMock) GetByUsername(ctx context.Context, username string) (User, error)

type User

type User struct {
	ID           uuid.UUID
	Name         string
	PasswordHash []byte
	Roles        []Role
	DateCreated  time.Time
}

User represents core user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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