user

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidRole = errors.New("not a valid Role")

Functions

func Module

func Module() fx.Option

func SetUserHandlerRoutes

func SetUserHandlerRoutes(server *echo.Echo, handler *UserHandler)

Types

type Role

type Role int

ENUM(user, mod, admin)

const (
	// RoleUser is a Role of type User.
	RoleUser Role = iota
	// RoleMod is a Role of type Mod.
	RoleMod
	// RoleAdmin is a Role of type Admin.
	RoleAdmin
)

func ParseRole

func ParseRole(name string) (Role, error)

ParseRole attempts to convert a string to a Role.

func (Role) IsValid

func (x Role) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Role) MarshalText

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

MarshalText implements the text marshaller method.

func (*Role) Scan

func (x *Role) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (Role) String

func (x Role) String() string

String implements the Stringer interface.

func (*Role) UnmarshalText

func (x *Role) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (Role) Value

func (x Role) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Service

type Service interface {
	Create(ctx context.Context, u User) (user User, err error)
	Get(ctx context.Context, userID uint) (user User, err error)
	GetByEmail(ctx context.Context, email string) (user User, err error)
	ListAll(ctx context.Context, role Role) (users []User, err error)
	UpdateAvatar(ctx context.Context, userID uint, newAvatarHref string) (user User, err error)
}

func NewUserService

func NewUserService(db *gorm.DB) Service

type User

type User struct {
	gorm.Model
	Email  string
	Name   string
	Role   Role
	Bio    string
	Avatar string
}

func (*User) IsAdmin

func (u *User) IsAdmin() bool

func (*User) IsMod

func (u *User) IsMod() bool

type UserHandler

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

func NewUserHandler

func NewUserHandler(service Service) *UserHandler

func (*UserHandler) ListAll

func (h *UserHandler) ListAll(c echo.Context) (err error)

type UserService

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

func (*UserService) Create

func (s *UserService) Create(ctx context.Context, u User) (user User, err error)

func (*UserService) Get

func (s *UserService) Get(ctx context.Context, userID uint) (user User, err error)

func (*UserService) GetByEmail

func (s *UserService) GetByEmail(ctx context.Context, email string) (user User, err error)

func (*UserService) ListAll

func (s *UserService) ListAll(ctx context.Context, role Role) (users []User, err error)

func (*UserService) UpdateAvatar

func (s *UserService) UpdateAvatar(ctx context.Context, userID uint, newAvatarHref string) (user User, err error)

Jump to

Keyboard shortcuts

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