data

package
v0.0.0-...-ff6508f Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 7 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
	Plan Plan
}

Models is the type for this package. Note that any model that is included as a member in this type is available to us throughout the application, anywhere that the app variable is used, provided that the model is also added in the New function.

func New

func New(dbPool *sql.DB) Models

New is the function used to create an instance of the data package. It returns the type Model, which embeds all the types we want to be available to our application.

type Plan

type Plan struct {
	ID                  int
	PlanName            string
	PlanAmount          int
	PlanAmountFormatted string
	CreatedAt           time.Time
	UpdatedAt           time.Time
}

Plan is the type for subscription plans

func (*Plan) AmountForDisplay

func (p *Plan) AmountForDisplay() string

AmountForDisplay formats the price we have in the DB as a currency string

func (*Plan) GetAll

func (p *Plan) GetAll() ([]*Plan, error)

func (*Plan) GetOne

func (p *Plan) GetOne(id int) (*Plan, error)

GetOne returns one plan by id

func (*Plan) SubscribeUserToPlan

func (p *Plan) SubscribeUserToPlan(user User, plan Plan) error

SubscribeUserToPlan subscribes a user to one plan by insert values into user_plans table

type User

type User struct {
	ID        int
	Email     string
	FirstName string
	LastName  string
	Password  string
	Active    int
	IsAdmin   int
	CreatedAt time.Time
	UpdatedAt time.Time
	Plan      *Plan
}

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

func (*User) Delete

func (u *User) Delete() error

Delete deletes one user from the database, by User.ID

func (*User) DeleteByID

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

DeleteByID deletes one user from the database, by ID

func (*User) GetAll

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

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

func (*User) GetByEmail

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

GetByEmail returns one user by email

func (*User) GetOne

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

GetOne returns one user by id

func (*User) Insert

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

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

func (*User) PasswordMatches

func (u *User) PasswordMatches(plainText string) (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 (*User) ResetPassword

func (u *User) ResetPassword(password string) error

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

func (*User) Update

func (u *User) Update() error

Update updates 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