menu

package
v0.0.0-...-fdd12d1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package menu implements all business logic regarding menus and related types.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is used when a specific Menu is requested but does not exist.
	ErrNotFound = errors.New("menu not found")

	// ErrInvalidID is used when an invalid UUID is provided.
	ErrInvalidID = errors.New("ID is not in its proper form")

	// ErrForbidden occurs when a user tries to do something that is forbidden to
	// them according to our access control policies.
	ErrForbidden = errors.New("Attempted action is not allowed")
)

Predefined errors identify expected failure conditions.

Functions

func Delete

func Delete(ctx context.Context, db *sqlx.DB, id string) error

Delete removes the menu identified by a given ID.

func Update

func Update(ctx context.Context, db *sqlx.DB, user auth.Claims, id string, update UpdateMenu, now time.Time) error

Update modifies data about a Menu. It will error if the specified ID is invalid or does not reference an existing Menu.

Types

type Menu struct {
	ID          string    `db:"menu_id" json:"id"`
	Name        string    `db:"name" json:"name"`
	CardID      string    `db:"card_id" json:"cardID"`
	UserID      string    `db:"user_id" json:"userID"`
	DateCreated time.Time `db:"date_created" json:"dateCreated"`
	DateUpdated time.Time `db:"date_updated" json:"dateUpdated"`
}

Menu is an datastructure for a Menu object.

func Create

func Create(ctx context.Context, db *sqlx.DB, user auth.Claims, nm NewMenu, now time.Time) (*Menu, error)

Create adds a Menu to the database. It returns the created Menu with fields like ID and DateCreated populated..

func List

func List(ctx context.Context, db *sqlx.DB) ([]Menu, error)

List gets all Menus from the database.

func Retrieve

func Retrieve(ctx context.Context, db *sqlx.DB, id string) (*Menu, error)

Retrieve finds the menu identified by a given ID.

type NewMenu

type NewMenu struct {
	Name   string `json:"name" validate:"required"`
	CardID string `json:"cardID"`
}

NewMenu is what we require from admin when adding a Menu.

type UpdateMenu

type UpdateMenu struct {
	Name   *string `json:"name"`
	CardID *string `json:"cardID"`
}

UpdateMenu defines what information may be provided to modify an existing Menu. 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.

Jump to

Keyboard shortcuts

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