data

package
v0.0.0-...-8a2e13d Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeActivation     = "activation"
	ScopeAuthentication = "authentication"
)

Variables

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

Functions

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 ValidatePasswordPlaintext

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

func ValidateTokenPlaintext

func ValidateTokenPlaintext(v *validator.Validator, tokenPlaintext 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 IMovieModel

type IMovieModel interface {
	Insert(movie *Movie) error
	Get(id int64) (*Movie, error)
	Update(movie *Movie) error
	Delete(id int64) error
	GetAll(title string, genres []string, filters Filters) ([]*Movie, Metadata, error)
}

type IPermissionModel

type IPermissionModel interface {
	GetAllForUser(userID int64) (Permissions, error)
	AddForUser(userID int64, codes ...string) error
}

type ITokenModel

type ITokenModel interface {
	New(userID int64, ttl time.Duration, scope string) (*Token, error)
	Insert(token *Token) error
	DeleteAllForUser(scope string, userID int64) error
}

type IUserModel

type IUserModel interface {
	Insert(user *User) error
	GetByEmail(email string) (*User, error)
	Update(user *User) error
	GetForToken(tokenScope, tokenPlaintext string) (*User, error)
}

type Metadata

type Metadata struct {
	CurrentPage  int `json:"current_page,omitempty"`
	PageSize     int `json:"page_size,omitempty"`
	FirstPage    int `json:"first_page,omitempty"`
	LastPage     int `json:"last_page,omitempty"`
	TotalRecords int `json:"total_records,omitempty"`
}

type MockMovieModel

type MockMovieModel struct{}

func (MockMovieModel) Delete

func (m MockMovieModel) Delete(id int64) error

func (MockMovieModel) Get

func (m MockMovieModel) Get(id int64) (*Movie, error)

func (MockMovieModel) GetAll

func (m MockMovieModel) GetAll(title string, genres []string, filters Filters) ([]*Movie, Metadata, error)

func (MockMovieModel) Insert

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

func (MockMovieModel) Update

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

type Models

type Models struct {
	Movies      IMovieModel
	Users       IUserModel
	Tokens      ITokenModel
	Permissions IPermissionModel
}

func NewMockModels

func NewMockModels() Models

func NewModels

func NewModels(db *sql.DB) Models

type Movie

type Movie struct {
	Id        int64     `json:"id"`
	Title     string    `json:"title"`
	Year      int32     `json:"year"`
	Runtime   int32     `json:"runtime"`
	Genres    []string  `json:"genres"`
	Version   int32     `json:"version"`
	CreatedAt time.Time `json:"-"`
}

type MovieModel

type MovieModel struct {
	DB *sql.DB
}

func (MovieModel) Delete

func (m MovieModel) Delete(id int64) error

func (MovieModel) Get

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

func (MovieModel) GetAll

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

func (MovieModel) Insert

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

func (MovieModel) Update

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

type PermissionModel

type PermissionModel struct {
	DB *sql.DB
}

func (PermissionModel) AddForUser

func (m PermissionModel) AddForUser(userID int64, codes ...string) error

func (PermissionModel) GetAllForUser

func (m PermissionModel) GetAllForUser(userID int64) (Permissions, error)

type Permissions

type Permissions []string

func (Permissions) Include

func (p Permissions) Include(code string) bool

type Token

type Token struct {
	Plaintext 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 (m TokenModel) DeleteAllForUser(scope string, userID int64) error

func (TokenModel) Insert

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

func (TokenModel) New

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

type User

type User struct {
	Id        int64     `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	Name      string    `json:"name"`
	Email     string    `json:"email"`
	Password  password  `json:"-"`
	Activated bool      `json:"activated"`
	Version   int       `json:"-"`
}

func (*User) IsAnonymous

func (u *User) IsAnonymous() bool

type UserModel

type UserModel struct {
	DB *sql.DB
}

func (UserModel) GetByEmail

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

func (UserModel) GetForToken

func (m UserModel) GetForToken(tokenScope, tokenPlaintext string) (*User, error)

func (UserModel) Insert

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

func (UserModel) Update

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

Jump to

Keyboard shortcuts

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