category

package
v0.0.0-...-2cbf9d5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package category contains category related CRUD functionality.

Index

Constants

This section is empty.

Variables

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

	// ErrInvalidID occurs when an ID is not in a valid form.
	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")
)

Functions

This section is empty.

Types

type Category

type Category struct {
	// contains filtered or unexported fields
}

Category manages the set of API's for category access.

func New

func New(log *log.Logger, db *sqlx.DB) Category

New constructs a Category for api access.

func (Category) Create

func (p Category) Create(ctx context.Context, traceID string, claims auth.Claims, n NewCategory, now time.Time) (Info, error)

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

func (Category) Delete

func (p Category) Delete(ctx context.Context, traceID string, id string) error

Delete removes the category identified by a given ID.

func (Category) Query

func (p Category) Query(ctx context.Context, traceID string, pageNumber int, rowsPerPage int) ([]Info, error)

Query gets all Categories from the database.

func (Category) QueryByID

func (p Category) QueryByID(ctx context.Context, traceID string, id string) (Info, error)

QueryByID finds the category identified by a given ID.

func (Category) Update

func (p Category) Update(ctx context.Context, traceID string, claims auth.Claims, id string, up UpdateCategory, now time.Time) error

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

type Info

type Info struct {
	ID          string         `db:"category_id" json:"id"`                // Unique identifier.
	Slug        string         `db:"slug" json:"slug"`                     // Unique category name
	Name        string         `db:"name" json:"name"`                     // Display name of the category.
	UserID      string         `db:"user_id" json:"user_id"`               // User ID of the category owner.
	ParentID    sql.NullString `db:"parent_id" json:"parent_id,omitempty"` // Parent category ID.
	DateCreated time.Time      `db:"date_created" json:"date_created"`     // When the category was added.
	DateUpdated time.Time      `db:"date_updated" json:"date_updated"`     // When the category record was last modified.
}

Info represents an individual category.

type NewCategory

type NewCategory struct {
	Slug     string `json:"slug" validate:"required"` // Unique category name
	Name     string `json:"name" validate:"required"` // Display name of the category.
	ParentID string `json:"parent_id"`                // Parent category ID.
}

NewCategory is what we require from clients when adding a Category.

type UpdateCategory

type UpdateCategory struct {
	Slug     *string `json:"slug"`      // Unique category slug
	Name     *string `json:"name"`      // Display name of the category.
	ParentID *string `json:"parent_id"` // Parent category ID.
}

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