wish

package
v0.0.0-...-f3f7782 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound abstracts the postgres not found error.
	ErrNotFound = errors.New("entity not found")

	// ErrInvalidID occurs when an ID is not in a valid form.
	ErrInvalidID = errors.New("ID is not in its proper form")
)

Functions

func Delete

func Delete(db *sqlx.DB, id int) error

Delete removes a wish from the database.

Types

type NewWish

type NewWish struct {
	OwnerID string  `json:"ownerid"`
	Title   string  `json:"title"`
	Price   float64 `json:"price"`
}

NewWish contains information needed to create a new Wish.

type UpdateWish

type UpdateWish struct {
	Title *string  `db:"title" json:"title"`
	Price *float64 `db:"price" json:"price"`
}

UpdateWish defines what information may be provided to modify an existing Wish. All fields are optional so clients can send just the fields they want changed. It uses pointer fields so we can differentiate between a field that was not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types but we make exceptions around marshalling/unmarshalling.

type Wish

type Wish struct {
	ID          int64     `db:"id" json:"id"`
	OwnerID     string    `db:"owner_id" json:"ownerid"`
	Title       string    `db:"title" json:"title"`
	Price       float64   `db:"price" json:"price"`
	DateCreated time.Time `db:"date_created" json:"date_created"`
	DateUpdated time.Time `db:"date_updated" json:"date_updated"`
}

Wish represents wish in database

func Create

func Create(db *sqlx.DB, nw *NewWish) (*Wish, error)

Create adds a Wish to the database. It returns the created Wish.

func GetWishesByUserID

func GetWishesByUserID(db *sqlx.DB, id string) ([]*Wish, error)

GetWishesByUserID gets all user wishes from the database.

func List

func List(db *sqlx.DB) ([]*Wish, error)

List retrieves a list of existing wishes from the database.

func Retrieve

func Retrieve(db *sqlx.DB, id int) (*Wish, error)

Retrieve gets the specified wish from the database.

func Update

func Update(db *sqlx.DB, id int, upd UpdateWish) (*Wish, error)

Update replaces a wish document in the database.

Jump to

Keyboard shortcuts

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