Documentation ¶
Index ¶
- Constants
- Variables
- type ListConfig
- type Repository
- type Store
- func (s *Store) Create(c domain.Category) (domain.Category, error)
- func (s *Store) Delete(id int) error
- func (s *Store) Exists(id int) bool
- func (s *Store) ExistsByName(name string) bool
- func (s *Store) ExistsBySlug(slug string) bool
- func (s *Store) Find(id int) (domain.Category, error)
- func (s *Store) FindByName(name string) (domain.Category, error)
- func (s *Store) FindByPost(id int) (domain.Category, error)
- func (s *Store) FindBySlug(slug string) (domain.Category, error)
- func (s *Store) FindParent(id int) (domain.Category, error)
- func (s *Store) List(meta params.Params, cfg ListConfig) (domain.Categories, int, error)
- func (s *Store) Update(c domain.Category) (domain.Category, error)
Constants ¶
const ( // The database table name for categories. TableName = "categories" // The database table name for the categories pivot. PivotTableName = "post_categories" )
Variables ¶
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 ¶
Store defines the data layer for categories.
func (*Store) Create ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.