category

package
v0.0.0-...-3eb6427 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CategoriesToStrSlice

func CategoriesToStrSlice(categories Categories) []string

CategoriesToStrSlice returns a slice of category names by the given categories slice

Types

type Categories

type Categories []Category

Categories is an array of Category

swagger:model

func ByNames

func ByNames(tx *gorm.DB, names []string) (*Categories, error)

ByNames returns a slice of Categories from the given slice of names.

func StrSliceToCategories

func StrSliceToCategories(tx *gorm.DB, sl []string) (*Categories, error)

StrSliceToCategories returns a slice of categories by the given category names

type Category

type Category struct {
	gorm.Model

	// Name is the name of the category
	Name *string `gorm:"not null;unique" json:"name"`

	// Slug is the human-friendly URL path to the category
	Slug *string `gorm:"not null;unique" json:"slug"`

	// ParentID is an optional parent ID.
	ParentID *uint `json:"parent_id,omitempty"`
}

Category is a type of label used to group resources, such as models and worlds, together. A category consists of a name, ID, and parentID. The parentID field should refer to a parent category, and supports a hierarchy of categories.

swagger:model

func ByName

func ByName(tx *gorm.DB, name string) (*Category, error)

ByName returns a category by the given name.

func BySlug

func BySlug(tx *gorm.DB, slug string) (*Category, error)

BySlug returns a category by the given slug.

func (Category) HasParent

func (c Category) HasParent() bool

HasParent returns true if the category has a ParentID assigned.

func (Category) IsParent

func (c Category) IsParent(tx *gorm.DB) (*bool, error)

IsParent returns true if there are categories that have the current category ID as Parent ID.

type Service

type Service struct{}

Service is a structure used in the REST API.

func (*Service) Create

func (cs *Service) Create(ctx context.Context, tx *gorm.DB,
	newCategory dtos.CreateCategory) (*Category, *gz.ErrMsg)

Create creates a new Category in DB using the data from the given CreateCategory dto.

func (*Service) Delete

func (cs *Service) Delete(ctx context.Context, tx *gorm.DB, categorySlug string) (*Category, *gz.ErrMsg)

Delete deletes a category by the given slug.

func (*Service) List

func (cs *Service) List(tx *gorm.DB) (*Categories, *gz.ErrMsg)

List returns a list of categories.

func (*Service) Update

func (cs *Service) Update(ctx context.Context, tx *gorm.DB,
	categorySlug string, cat dtos.UpdateCategory) (*Category, *gz.ErrMsg)

Update updates a category in DB using the data from the given Service struct. Returns a Service.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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