Version: v0.0.0-...-fdd12d1 Latest Latest

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



Package card implements all business logic regarding cards and related types.



This section is empty.


View Source
var (
	// ErrNotFound is used when a specific Card is requested but does not exist.
	ErrNotFound = errors.New("card 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.


func Delete

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

Delete removes the card identified by a given ID.

func Update

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

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


type Card

type Card struct {
	ID          string    `db:"card_id" json:"id"`
	Name        string    `db:"name" json:"name"`
	Content     string    `db:"content" json:"content"`
	UserID      string    `db:"user_id" json:"userID"`
	DateCreated time.Time `db:"date_created" json:"dateCreated"`
	DateUpdated time.Time `db:"date_updated" json:"dateUpdated"`

Card is an datastructure for a Card object.

func Create

func Create(ctx context.Context, db *sqlx.DB, user auth.Claims, nc NewCard, now time.Time) (*Card, error)

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

func List

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

List gets all Cards from the database.

func Retrieve

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

Retrieve finds the card identified by a given ID.

type NewCard

type NewCard struct {
	Name    string `json:"name" validate:"required"`
	Content string `json:"content"`

NewCard is what we require from admin when adding a Card.

type UpdateCard

type UpdateCard struct {
	Name    *string `json:"name"`
	Content *string `json:"content"`

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