data

package
v0.0.0-...-bf14b0d Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Models

type Models struct {
	User User
}

Model is a type for the data package

func New

func New(dbPtr *sql.DB) Models

Creates an instance of the data package. Returns Model struct which has all types available to the app

type User

type User struct {
	ID        int       `json:"id"`
	Email     string    `json:"email"`
	FirstName string    `json:"first_name,omitempty"`
	LastName  string    `json:"last_name,omitempty"`
	Password  string    `json:"-"`
	Active    int       `json:"active"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Single User

func (*User) Delete

func (u *User) Delete() error

Delete one user from the database, by User.ID

func (*User) DeleteByID

func (u *User) DeleteByID(id int) error

Delete one user from the database, by ID

func (*User) GetAll

func (user *User) GetAll() ([]*User, error)

Get list of users from DB, sorted by last name

func (*User) GetByEmail

func (u *User) GetByEmail(email string) (*User, error)

Get user by email

func (*User) GetOne

func (u *User) GetOne(id int) (*User, error)

Get user by id

func (*User) Insert

func (u *User) Insert(user User) (int, error)

Insert a new user into the database, and returns the ID of the new user

func (*User) PasswordMatches

func (u *User) PasswordMatches(userInput string) (bool, error)

Compare a user supplied password with the hash we have stored in the database. If the password and hash match, we return true; otherwise, we return false.

func (*User) Update

func (u *User) Update() error

Update one user in the database, using the information stored in the receiver u

Jump to

Keyboard shortcuts

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