categories

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The database table name for categories.
	TableName = "categories"
	// The database table name for the categories pivot.
	PivotTableName = "post_categories"
)

Variables

View Source
var (
	// ErrCategoryExists is returned by validate when
	// a category already exists.
	ErrCategoryExists = errors.New("category already exists")
)

Functions

This section is empty.

Types

type ListConfig

type ListConfig struct {
	Resource string
}

ListConfig defines the configuration for obtaining categories for Selects. Categories can be filtered by resources

type Repository

type Repository interface {
	List(meta params.Params, cfg ListConfig) (domain.Categories, int, error)
	Find(id int) (domain.Category, error)
	FindByPost(id int) (domain.Category, error)
	FindBySlug(slug string) (domain.Category, error)
	FindByName(name string) (domain.Category, error)
	FindParent(id int) (domain.Category, error)
	Create(c domain.Category) (domain.Category, error)
	Update(c domain.Category) (domain.Category, error)
	Delete(id int) error
	Exists(id int) bool
	ExistsByName(name string) bool
	ExistsBySlug(slug string) bool
}

Repository defines methods for categories to interact with the database.

type Store

type Store struct {
	*config.Config
}

Store defines the data layer for categories.

func New

func New(cfg *config.Config) *Store

New

Creates a new categories store.

func (*Store) Create

func (s *Store) Create(c domain.Category) (domain.Category, error)

Create

Returns a new category upon creation. Returns errors.CONFLICT if the the category (name) already exists. Returns errors.INTERNAL if the SQL query was invalid or the function could not get the newly created ID.

func (*Store) Delete

func (s *Store) Delete(id int) error

Delete

Returns nil if the category was successfully deleted. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.NOTFOUND if the category was not found.

func (*Store) Exists

func (s *Store) Exists(id int) bool

Exists

Returns a bool indicating if the category exists by ID. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) ExistsByName

func (s *Store) ExistsByName(name string) bool

ExistsByName

Returns a bool indicating if the category exists by name. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) ExistsBySlug

func (s *Store) ExistsBySlug(slug string) bool

ExistsBySlug

Returns a bool indicating if the category exists by slug. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) Find

func (s *Store) Find(id int) (domain.Category, error)

Find

Returns a category by searching with the given ID. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the category was not found by the given ID.

func (*Store) FindByName

func (s *Store) FindByName(name string) (domain.Category, error)

FindByName

Returns a category by searching with the given name. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the category was not found by the given slug.

func (*Store) FindByPost

func (s *Store) FindByPost(id int) (domain.Category, error)

FindByPost

Returns a category by searching with the given post ID. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the category was not found by the given post ID.

func (*Store) FindBySlug

func (s *Store) FindBySlug(slug string) (domain.Category, error)

FindBySlug

Returns a category by searching with the given slug. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the category was not found by the given slug.

func (*Store) FindParent

func (s *Store) FindParent(id int) (domain.Category, error)

FindParent

Returns a category by searching with the given parent ID. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the category was not found by the given slug.

func (*Store) List

func (s *Store) List(meta params.Params, cfg ListConfig) (domain.Categories, int, error)

List

Returns a slice of categories with the total amount. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.NOTFOUND if there are no categories available.

func (*Store) Update

func (s *Store) Update(c domain.Category) (domain.Category, error)

Update

Returns an updated category. Returns errors.CONFLICT if the validation failed. Returns errors.INTERNAL if the SQL query was invalid or the function could not obtain the newly created ID.

Jump to

Keyboard shortcuts

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