data

package
v0.0.0-...-d23d5bc Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeActivation     = "activation"
	ScopeAuthentication = "authentication"
	ScopePasswordReset  = "password-reset"
)

Variables

View Source
var (
	ErrRecordNotFound = errors.New("record not found")
	ErrEditConflict   = errors.New("edit conflict")
)
View Source
var (
	ErrDuplicateEmail = errors.New("duplicate email")
	Anonymous         = &User{}
)
View Source
var ErrInvalidRuntimeFormat = errors.New("invalid runtime format")

Functions

func ValidTokenText

func ValidTokenText(v *validator.Validator, text string)

func ValidateEmail

func ValidateEmail(v *validator.Validator, email string)

func ValidateFilters

func ValidateFilters(v *validator.Validator, f Filters)

func ValidateMovie

func ValidateMovie(v *validator.Validator, movie *Movie)

func ValidatePasswordText

func ValidatePasswordText(v *validator.Validator, password string)

func ValidateUser

func ValidateUser(v *validator.Validator, user *User)

Types

type Filters

type Filters struct {
	Page         int
	PageSize     int
	Sort         string
	SortSafeList []string
}

type MetaData

type MetaData struct {
	CurrentPage int `json:"current_page"`
	PageSize    int `json:"page_size"`
	FirstPage   int `json:"first_page"`
	LastPage    int `json:"last_page"`
	Total       int `json:"total"`
}

type Model

type Model struct {
	Movie      MovieModel
	User       UserModel
	Token      TokenModel
	Permission PermissionModel
}

func NewModel

func NewModel(db *sql.DB) Model

type Movie

type Movie struct {
	ID int64 `json:"id"`

	Title string `json:"title"`
	Year  int32  `json:"year"`

	Runtime Runtime  `json:"runtime"`
	Genres  []string `json:"genres"`

	Version   int32     `json:"version"`
	CreatedAt time.Time `json:"created_at"`
}

type MovieModel

type MovieModel struct {
	DB *sql.DB
}

func (MovieModel) Delete

func (m MovieModel) Delete(id int64) error

func (MovieModel) Insert

func (m MovieModel) Insert(movie *Movie) error

func (MovieModel) Select

func (m MovieModel) Select(id int64) (*Movie, error)

func (MovieModel) SelectMany

func (m MovieModel) SelectMany(title string, genres []string, filters Filters) ([]*Movie, MetaData, error)

func (MovieModel) Update

func (m MovieModel) Update(movie *Movie) error

type Password

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

func (*Password) Hash

func (p *Password) Hash(text string) error

func (*Password) Matches

func (p *Password) Matches(text string) (bool, error)

type PermissionModel

type PermissionModel struct {
	DB *sql.DB
}

func (PermissionModel) GetUserPermissions

func (p PermissionModel) GetUserPermissions(userID int64) (Permissions, error)

func (PermissionModel) GrantUser

func (p PermissionModel) GrantUser(userID int64, codes ...string) error

type Permissions

type Permissions []string

func (Permissions) Contains

func (p Permissions) Contains(code string) bool

type Runtime

type Runtime int32

func (Runtime) MarshalJSON

func (r Runtime) MarshalJSON() ([]byte, error)

func (*Runtime) UnmarshalJSON

func (r *Runtime) UnmarshalJSON(value []byte) error

type Token

type Token struct {
	Text   string    `json:"token"`
	Hash   []byte    `json:"-"`
	UserID int64     `json:"-"`
	Expiry time.Time `json:"expiry"`
	Scope  string    `json:"-"`
}

type TokenModel

type TokenModel struct {
	DB *sql.DB
}

func (TokenModel) DeleteAllForUser

func (t TokenModel) DeleteAllForUser(scope string, userID int64) error

func (TokenModel) Insert

func (t TokenModel) Insert(token *Token) error

func (TokenModel) New

func (t TokenModel) New(userID int64, expiry time.Duration, scope string) (*Token, error)

type User

type User struct {
	ID int64 `json:"id"`

	Name  string `json:"name"`
	Email string `json:"email"`

	Password  Password `json:"-"`
	Activated bool     `json:"activated"`

	Version int32 `json:"-"`

	CreatedAt time.Time `json:"created_at"`
}

func (*User) IsAnonymous

func (u *User) IsAnonymous() bool

type UserModel

type UserModel struct {
	DB *sql.DB
}

func (*UserModel) GetByEmail

func (u *UserModel) GetByEmail(email string) (*User, error)

func (*UserModel) GetForToken

func (u *UserModel) GetForToken(scope, text string) (*User, error)

func (*UserModel) Insert

func (u *UserModel) Insert(user *User) error

func (*UserModel) Update

func (u *UserModel) Update(user *User) error

Jump to

Keyboard shortcuts

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