data

package
v0.0.0-...-c651e18 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PostgresRepository

type PostgresRepository struct {
	Conn *sql.DB
}

func NewPostgresRepository

func NewPostgresRepository(pool *sql.DB) *PostgresRepository

func (*PostgresRepository) DeleteByID

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

DeleteByID deletes one user from the database, by ID

func (*PostgresRepository) GetAll

func (u *PostgresRepository) GetAll() ([]*User, error)

GetAll returns a slice of all users, sorted by last name

func (*PostgresRepository) GetByEmail

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

GetByEmail returns one user by email

func (*PostgresRepository) GetOne

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

GetOne returns one user by id

func (*PostgresRepository) Insert

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

Insert inserts a new user into the database, and returns the ID of the newly inserted row

func (*PostgresRepository) PasswordMatches

func (u *PostgresRepository) PasswordMatches(plainText string, user User) (bool, error)

PasswordMatches uses Go's bcrypt package to compare a user supplied password with the hash we have stored for a given user in the database. If the password and hash match, we return true; otherwise, we return false.

func (*PostgresRepository) ResetPassword

func (u *PostgresRepository) ResetPassword(password string, user User) error

ResetPassword is the method we will use to change a user's password.

func (*PostgresRepository) Update

func (u *PostgresRepository) Update(user User) error

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

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"`
}

User is the structure which holds one user from the database.

Jump to

Keyboard shortcuts

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