models

package
v0.0.0-...-23da318 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PasswordHashCost = 12
)

Variables

View Source
var (
	ErrDuplicateEmail     = errors.New("models: duplicate email")
	ErrInvalidCredentials = errors.New("models: invalid credentials")
	ErrNoRecord           = errors.New("models: no matching record found")
)

Functions

This section is empty.

Types

type Review

type Review struct {
	UserID    int
	SnippetID int
	Reviews   uint8
}

type ReviewModel

type ReviewModel struct {
	DB *sql.DB
}

ReviewModel wraps a database connection pool

func (*ReviewModel) Exists

func (m *ReviewModel) Exists(userID, snippetID int) (bool, error)

func (*ReviewModel) Get

func (m *ReviewModel) Get(userID, snippetID int) (*Review, error)

func (*ReviewModel) Insert

func (m *ReviewModel) Insert(userID, snippetID int) error

func (*ReviewModel) Update

func (m *ReviewModel) Update(userID, snippetID int) error

type ReviewModelInterface

type ReviewModelInterface interface {
	Insert(userID, snippetID int) error
	Exists(userID, snippetID int) (bool, error)
	Get(userID, snippetID int) (*Review, error)
	Update(userID, snippetID int) error
}

type Snippet

type Snippet struct {
	ID      int
	Title   string
	Content string
	Created time.Time
	Expires time.Time
}

type SnippetModel

type SnippetModel struct {
	DB *sql.DB
}

SnippetModel wraps a database connection pool

func (*SnippetModel) Get

func (m *SnippetModel) Get(id int) (*Snippet, error)

func (*SnippetModel) Insert

func (m *SnippetModel) Insert(title, content string, expires int) (int, error)

func (*SnippetModel) Latest

func (m *SnippetModel) Latest() ([]*Snippet, error)

type SnippetModelInterface

type SnippetModelInterface interface {
	Insert(title, content string, expires int) (int, error)
	Get(id int) (*Snippet, error)
	Latest() ([]*Snippet, error)
}

type User

type User struct {
	ID             int
	Name           string
	Email          string
	HashedPassword []byte
	Created        time.Time
	Owner          bool
}

type UserModel

type UserModel struct {
	DB *sql.DB
}

UserModel wraps a database connection pool

func (*UserModel) Authenticate

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

func (*UserModel) Authorize

func (m *UserModel) Authorize(id int) (bool, error)

func (*UserModel) Exists

func (m *UserModel) Exists(id int) (bool, error)

func (*UserModel) Get

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

func (*UserModel) Insert

func (m *UserModel) Insert(name, email, password string, owner bool) error

func (*UserModel) Owner

func (m *UserModel) Owner() (bool, error)

func (*UserModel) PasswordUpdate

func (m *UserModel) PasswordUpdate(id int, currentPassword, newPassword string) error

type UserModelInterface

type UserModelInterface interface {
	Insert(name, email, password string, owner bool) error
	Authenticate(email, password string) (int, error)
	Authorize(id int) (bool, error)
	Exists(id int) (bool, error)
	Get(id int) (*User, error)
	Owner() (bool, error)
	PasswordUpdate(id int, currentPassword, newPassword string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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