roles

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The database table name for roles.
	TableName = "roles"
)

Variables

View Source
var (
	// ErrRoleExists is returned by validate when
	// a role name already exists.
	ErrRoleExists = errors.New("role already exists")
)

Functions

This section is empty.

Types

type Repository

type Repository interface {
	List() (domain.Roles, error)
	Find(id int) (domain.Role, error)
	Create(r domain.Role) (domain.Role, error)
	Update(r domain.Role) (domain.Role, error)
	Exists(name string) bool
}

Repository defines methods for roles to interact with the database.

type Store

type Store struct {
	*config.Config
}

Store defines the data layer for roles.

func New

func New(cfg *config.Config) *Store

New

Creates a new roles store.

func (*Store) Create

func (s *Store) Create(r domain.Role) (domain.Role, error)

Create

Returns a new role upon creation. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.CONFLICT if the the role ID already exists.

func (*Store) Exists

func (s *Store) Exists(name string) bool

Exists

Returns a bool indicating if the role exists by ID. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) Find

func (s *Store) Find(id int) (domain.Role, error)

Find

Returns a roles by searching with the given ID. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the role was not found by the given ID.

func (*Store) List

func (s *Store) List() (domain.Roles, error)

List

Returns a slice of categories with the total amount. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.NOTFOUND if there are no categories available.

func (*Store) Update

func (s *Store) Update(r domain.Role) (domain.Role, error)

Update

Returns an updated role. Returns errors.CONFLICT if the validation failed. Returns errors.INTERNAL if the SQL query was invalid or the function could not obtain the newly created ID.

Jump to

Keyboard shortcuts

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