data

package
v0.0.0-...-22da921 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordNotFound     = errors.New("record not found")
	ErrInvalidCredentials = errors.New("invalid credentials")
)
View Source
var (
	ErrDuplicateEmail = errors.New("duplicate email")
)

Functions

func ValidateFilters

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

func ValidateUser

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

Types

type Filters

type Filters struct {
	Page         int
	PageSize     int
	Sort         string
	SortSafelist []string
}
type Link struct {
	ID             int64
	Title          string
	Type           string
	URL            sql.NullString
	Content        sql.NullString
	Likes          int64
	Tags           []string
	CreatedAt      time.Time
	HumanCreatedAt string
}

func (*Link) FormatCreatedAt

func (l *Link) FormatCreatedAt()

type LinkModel

type LinkModel struct {
	DB *sql.DB
}

func (LinkModel) All

func (l LinkModel) All(title string, tags []string, filters Filters) ([]*Link, Pagedata, error)

func (LinkModel) Delete

func (l LinkModel) Delete(id int64) error

func (LinkModel) Get

func (l LinkModel) Get(id int64) (*Link, error)

func (LinkModel) Insert

func (l LinkModel) Insert(link *Link) error

type Models

type Models struct {
	Links LinkModel
	Users UserModel
}

func NewModels

func NewModels(db *sql.DB) Models

type Pagedata

type Pagedata 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 User

type User struct {
	ID             int64
	Email          string
	HashedPassword []byte
	CreatedAt      time.Time
}

type UserModel

type UserModel struct {
	DB *sql.DB
}

func (*UserModel) Authenticate

func (u *UserModel) Authenticate(email, password string) (int, error)

func (*UserModel) Get

func (um *UserModel) Get(id int) (*User, error)

func (*UserModel) Insert

func (u *UserModel) Insert(email, password string) error

Jump to

Keyboard shortcuts

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