models

package
v0.0.0-...-80a305e Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Snippet

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

Snippet type holds the data for an individual snippet.

type SnippetModel

type SnippetModel struct {
	DB *sql.DB
}

SnippetModel type wraps a sql.Db connection pool.

func (*SnippetModel) Get

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

Get return a specific snippet based on its id.

func (*SnippetModel) Insert

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

Insert return a new snippet into the database.

func (*SnippetModel) Latest

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

Latest return the 10 most recently created snippets.

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
}

User is a new User type.

type UserModel

type UserModel struct {
	DB *sql.DB
}

User Model wraps a database connection pool.

func (*UserModel) Authenticate

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

Authenticate method verifys whether a user exitsts with the provided emal address and password. It returns the relevant user ID if they do.

func (*UserModel) Exists

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

Exists method checks if a user exists with a specific ID.

func (*UserModel) Get

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

Get method returns user's info

func (*UserModel) Insert

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

Insert method adds a new record to the "users" table.

func (*UserModel) PasswordUpdate

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

type UserModelInteraface

type UserModelInteraface interface {
	Insert(name, email, password string) error
	Authenticate(email, password string) (int, error)
	Exists(id int) (bool, error)
	Get(id int) (*User, 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