Documentation
¶
Overview ¶
Package category contains category related CRUD functionality.
Index ¶
- Variables
- type Category
- func (p Category) Create(ctx context.Context, traceID string, claims auth.Claims, n NewCategory, ...) (Info, error)
- func (p Category) Delete(ctx context.Context, traceID string, id string) error
- func (p Category) Query(ctx context.Context, traceID string, pageNumber int, rowsPerPage int) ([]Info, error)
- func (p Category) QueryByID(ctx context.Context, traceID string, id string) (Info, error)
- func (p Category) Update(ctx context.Context, traceID string, claims auth.Claims, id string, ...) error
- type Info
- type NewCategory
- type UpdateCategory
Constants ¶
This section is empty.
Variables ¶
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 (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) Query ¶
func (p Category) Query(ctx context.Context, traceID string, pageNumber int, rowsPerPage int) ([]Info, error)
Query gets all Categories from the database.
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.