cart

package
v0.0.0-...-53bd342 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, db sqlx.ExtContext, cart Cart) error

Create inserts a new user's cart.

func CreateItem

func CreateItem(ctx context.Context, db sqlx.ExtContext, item Item) error

CreateItem inserts a new item in the user's cart.

func Delete

func Delete(ctx context.Context, db sqlx.ExtContext, userID string) error

Delete deletes a user's cart.

func DeleteItem

func DeleteItem(ctx context.Context, db sqlx.ExtContext, userID string, courseID string) error

DeleteItem drops an item from the user's cart.

func HandleCreateItem

func HandleCreateItem(db *sqlx.DB) web.Handler

HandleCreateItem adds a new item in the user's cart.

func HandleDelete

func HandleDelete(db *sqlx.DB) web.Handler

HandleDelete flushes the user's cart. It also drops all related items in cascade.

func HandleDeleteItem

func HandleDeleteItem(db *sqlx.DB) web.Handler

HandleDeleteItem deletes an item from the user's cart.

func HandleShow

func HandleShow(db *sqlx.DB) web.Handler

HandleShow returns the cart of the user. Returns an empty cart if the user has no cart.

Types

type Cart

type Cart struct {
	UserID    string    `json:"-" db:"user_id"`
	CreatedAt time.Time `json:"createdAt" db:"created_at"`
	UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
	Version   int       `json:"-" db:"version"`
	Items     []Item    `json:"items" db:"-"`
}

Cart models the users' carts. Each user can have only a cart at a time.

func Fetch

func Fetch(ctx context.Context, db sqlx.ExtContext, userID string) (Cart, error)

Fetch returns the passed user's cart, if any.

func Update

func Update(ctx context.Context, db sqlx.ExtContext, cart Cart) (Cart, error)

Update updates a user's cart, relying on optimistic lock to deal with data races.

func Upsert

func Upsert(ctx context.Context, db sqlx.ExtContext, userID string) (Cart, error)

Upsert updates a user's cart if it exists. It creates it otherwise.

type Item

type Item struct {
	UserID    string    `json:"-" db:"user_id"`
	CourseID  string    `json:"courseId" db:"course_id"`
	CreatedAt time.Time `json:"createdAt" db:"created_at"`
	UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
}

Item models the item of a cart. A cart can have many items.

func FetchItems

func FetchItems(ctx context.Context, db sqlx.ExtContext, userID string) ([]Item, error)

FetchItems returns all the user's cart items.

type ItemNew

type ItemNew struct {
	CourseID string `json:"courseId" db:"course_id"`
}

ItemNew models the data required to insert a new item on the user's cart.

Jump to

Keyboard shortcuts

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