data

package
v0.0.0-...-31d623c Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeActivation     = "activation"
	ScopeAuthentication = "authentication"
)
View Source
const (
	USER_ROLE         = "user"
	ADMIN_ROLE        = "admin"
	ANALYTIC_ROLE     = "analytic"
	ITEM_CREATOR_ROLE = "item_creator"
)

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 ValidateCursors

func ValidateCursors(v *validator.Validator, c Cursor)

func ValidateEmail

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

func ValidateFilters

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

func ValidateItem

func ValidateItem(v *validator.Validator, item *Item)

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 Cursor

type Cursor struct {
	LastSortVal interface{} `json:"last_sort_val,omitempty"`
	LastID      int64       `json:"last_id,omitempty"`
}

type Filters

type Filters struct {
	PageSize     int
	Sort         string
	SortSafelist []string
}

type Item

type Item struct {
	ID        int64     `json:"id"`
	CreatedAt time.Time `json:"-"`
	Name      string    `json:"name"`
	Category  string    `json:"category"`
	CreatedBy int64     `json:"created_by"`
	Quantity  int       `json:"quantity"`
	Pcode     string    `json:"pcode"`
	ImageURL  string    `json:"image_url,omitempty"`
	Version   int32     `json:"version"`
}

type ItemModel

type ItemModel struct {
	DB *sql.DB
}

func (ItemModel) Delete

func (i ItemModel) Delete(id int64) error

func (ItemModel) Get

func (i ItemModel) Get(id int64) (*Item, error)

func (ItemModel) GetAll

func (i ItemModel) GetAll(name string, category_name string, filters Filters, cursor *Cursor) ([]*Item, Metadata, error)

func (ItemModel) Insert

func (i ItemModel) Insert(item *Item) error

func (ItemModel) Update

func (i ItemModel) Update(item *Item) error

type Metadata

type Metadata struct {
	PageSize     int     `json:"page_size,omitempty"`
	TotalRecords int     `json:"total_records,omitempty"`
	Cursor       *Cursor `json:"cursor,omitempty"`
}

type Models

type Models struct {
	Items  ItemModel
	Users  UserModel
	Tokens TokenModel
}

func NewModels

func NewModels(db *sql.DB) Models

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

DeleteAllForUser() deletes all tokens for a specific user and scope.

func (TokenModel) Insert

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

Insert() adds the data for a specific token to the tokens table.

func (TokenModel) New

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

The New() method is a shortcut which creates a new Token struct and then inserts the data in the tokens table.

type User

type User struct {
	ID        int64     `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	FirstName string    `json:"first_name"`
	LastName  string    `json:"last_name"`
	Email     string    `json:"email"`
	Pcode     string    `json:"pcode"`
	Phone     string    `json:"phone,omitempty"`
	ImageURL  string    `json:"image_url,omitempty"`
	Password  password  `json:"-"`
	Activated bool      `json:"activated"`
	Role      string    `json:"-"`
	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