Documentation
¶
Index ¶
- func NewPlugin() plugin.Plugin
- func RegisterCategoryRoutes(router fiber.Router, db database.Database, config *Config, ...)
- func RegisterRoutes(router fiber.Router, db database.Database, config *Config)
- func RegisterRoutesWithService(router fiber.Router, db database.Database, config *Config, ...)
- func RegisterTagRoutes(router fiber.Router, db database.Database, config *Config, ...)
- type Category
- type CategoryConverter
- func (c *CategoryConverter) CreateDTOToModel(dto CategoryCreateDTO) Category
- func (c *CategoryConverter) ModelToResponseDTO(model Category) CategoryResponseDTO
- func (c *CategoryConverter) ModelsToResponseDTOs(models []Category) []CategoryResponseDTO
- func (c *CategoryConverter) UpdateDTOToModel(dto CategoryUpdateDTO) Category
- type CategoryCreateDTO
- type CategoryResource
- type CategoryResponseDTO
- type CategoryTreeNode
- type CategoryUpdateDTO
- type Config
- type ResourceAttachDTO
- type ServiceProvider
- type Tag
- type TagConverter
- type TagCreateDTO
- type TagResource
- type TagResponseDTO
- type TagUpdateDTO
- type TaxonomyHooks
- func (h *TaxonomyHooks) CategoryCreateHook(c fiber.Ctx, dto CategoryCreateDTO, model *Category) error
- func (h *TaxonomyHooks) CategoryDeleteHook(_ fiber.Ctx, _ any) error
- func (h *TaxonomyHooks) CategoryGetAllHook(_ fiber.Ctx, _ *[]query.Condition, _ *[]crud.OrderByClause) error
- func (h *TaxonomyHooks) CategoryGetByIDHook(_ fiber.Ctx, _ any) error
- func (h *TaxonomyHooks) CategoryUpdateHook(c fiber.Ctx, dto CategoryUpdateDTO, model *Category) error
- func (h *TaxonomyHooks) TagCreateHook(c fiber.Ctx, dto TagCreateDTO, model *Tag) error
- func (h *TaxonomyHooks) TagDeleteHook(_ fiber.Ctx, _ any) error
- func (h *TaxonomyHooks) TagGetAllHook(_ fiber.Ctx, _ *[]query.Condition, _ *[]crud.OrderByClause) error
- func (h *TaxonomyHooks) TagGetByIDHook(_ fiber.Ctx, _ any) error
- func (h *TaxonomyHooks) TagUpdateHook(_ fiber.Ctx, dto TagUpdateDTO, model *Tag) error
- type TaxonomyPlugin
- func (p *TaxonomyPlugin) Dependencies() []string
- func (p *TaxonomyPlugin) GetOpenAPIResources() []plugin.OpenAPIResource
- func (p *TaxonomyPlugin) GetService() *TaxonomyService
- func (p *TaxonomyPlugin) Handler() fiber.Handler
- func (p *TaxonomyPlugin) Initialize(config map[string]interface{}) error
- func (p *TaxonomyPlugin) MigrationDependencies() []string
- func (p *TaxonomyPlugin) MigrationSource() interface{}
- func (p *TaxonomyPlugin) Name() string
- func (p *TaxonomyPlugin) SetupEndpoints(router fiber.Router) error
- type TaxonomyService
- func (s *TaxonomyService) AttachCategory(ctx context.Context, categoryID uuid.UUID, resource string, ...) error
- func (s *TaxonomyService) AttachTag(ctx context.Context, tagID uuid.UUID, resource string, resourceID uuid.UUID) error
- func (s *TaxonomyService) BuildCategoryTree(categories []Category) []*CategoryTreeNode
- func (s *TaxonomyService) DetachCategory(ctx context.Context, categoryID uuid.UUID, resource string, ...) error
- func (s *TaxonomyService) DetachTag(ctx context.Context, tagID uuid.UUID, resource string, resourceID uuid.UUID) error
- func (s *TaxonomyService) GetAllCategories(ctx context.Context) ([]Category, error)
- func (s *TaxonomyService) GetCategoriesForResource(ctx context.Context, resource string, resourceID uuid.UUID) ([]Category, error)
- func (s *TaxonomyService) GetCategoriesForResources(ctx context.Context, resource string, resourceIDs []uuid.UUID) (map[uuid.UUID][]Category, error)
- func (s *TaxonomyService) GetCategoryDepth(ctx context.Context, id uuid.UUID) (int, error)
- func (s *TaxonomyService) GetResourceIDsByCategorySlug(ctx context.Context, resource, slug string) ([]uuid.UUID, error)
- func (s *TaxonomyService) GetResourceIDsByTagSlug(ctx context.Context, resource, slug string) ([]uuid.UUID, error)
- func (s *TaxonomyService) GetTagsForResource(ctx context.Context, resource string, resourceID uuid.UUID) ([]Tag, error)
- func (s *TaxonomyService) GetTagsForResources(ctx context.Context, resource string, resourceIDs []uuid.UUID) (map[uuid.UUID][]Tag, error)
- func (s *TaxonomyService) InvalidateCategoryCache()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterCategoryRoutes ¶
func RegisterRoutes ¶
func RegisterRoutesWithService ¶ added in v0.2.4
func RegisterTagRoutes ¶
Types ¶
type Category ¶
type Category struct {
ID uuid.UUID `json:"id" db:"id"`
ParentID *uuid.UUID `json:"parent_id,omitempty" db:"parent_id"`
Name string `json:"name" db:"name"`
Slug string `json:"slug" db:"slug"`
Description string `json:"description" db:"description"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt *time.Time `json:"updated_at,omitempty" db:"updated_at"`
}
type CategoryConverter ¶
type CategoryConverter struct{}
func (*CategoryConverter) CreateDTOToModel ¶
func (c *CategoryConverter) CreateDTOToModel(dto CategoryCreateDTO) Category
func (*CategoryConverter) ModelToResponseDTO ¶
func (c *CategoryConverter) ModelToResponseDTO(model Category) CategoryResponseDTO
func (*CategoryConverter) ModelsToResponseDTOs ¶
func (c *CategoryConverter) ModelsToResponseDTOs(models []Category) []CategoryResponseDTO
func (*CategoryConverter) UpdateDTOToModel ¶
func (c *CategoryConverter) UpdateDTOToModel(dto CategoryUpdateDTO) Category
type CategoryCreateDTO ¶
type CategoryResource ¶
type CategoryResource struct {
ID uuid.UUID `json:"id" db:"id"`
CategoryID uuid.UUID `json:"category_id" db:"category_id"`
Resource string `json:"resource" db:"resource"`
ResourceID uuid.UUID `json:"resource_id" db:"resource_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
func (CategoryResource) TableName ¶
func (CategoryResource) TableName() string
type CategoryResponseDTO ¶
type CategoryTreeNode ¶
type CategoryTreeNode struct {
ID uuid.UUID `json:"id"`
ParentID *uuid.UUID `json:"parent_id,omitempty"`
Name string `json:"name"`
Slug string `json:"slug"`
Description string `json:"description,omitempty"`
Children []*CategoryTreeNode `json:"children,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
type CategoryUpdateDTO ¶
type Config ¶
type Config struct {
Database database.Database
AllowedTypes []string `json:"allowed_types" yaml:"allowed_types"`
MaxDepth int `json:"max_depth" yaml:"max_depth"`
PaginationLimit int `json:"pagination_limit" yaml:"pagination_limit"`
MaxPaginationLimit int `json:"max_pagination_limit" yaml:"max_pagination_limit"`
}
func DefaultConfig ¶
func DefaultConfig() Config
func (*Config) IsAllowedType ¶
type ResourceAttachDTO ¶
type ServiceProvider ¶ added in v0.2.4
type ServiceProvider interface {
GetService() *TaxonomyService
}
type Tag ¶
type TagConverter ¶
type TagConverter struct{}
func (*TagConverter) CreateDTOToModel ¶
func (c *TagConverter) CreateDTOToModel(dto TagCreateDTO) Tag
func (*TagConverter) ModelToResponseDTO ¶
func (c *TagConverter) ModelToResponseDTO(model Tag) TagResponseDTO
func (*TagConverter) ModelsToResponseDTOs ¶
func (c *TagConverter) ModelsToResponseDTOs(models []Tag) []TagResponseDTO
func (*TagConverter) UpdateDTOToModel ¶
func (c *TagConverter) UpdateDTOToModel(dto TagUpdateDTO) Tag
type TagCreateDTO ¶
type TagResource ¶
type TagResource struct {
ID uuid.UUID `json:"id" db:"id"`
TagID uuid.UUID `json:"tag_id" db:"tag_id"`
Resource string `json:"resource" db:"resource"`
ResourceID uuid.UUID `json:"resource_id" db:"resource_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
func (TagResource) TableName ¶
func (TagResource) TableName() string
type TagResponseDTO ¶
type TagUpdateDTO ¶
type TaxonomyHooks ¶
type TaxonomyHooks struct {
// contains filtered or unexported fields
}
func NewTaxonomyHooks ¶
func NewTaxonomyHooks(db database.Database, config *Config, service *TaxonomyService) *TaxonomyHooks
func (*TaxonomyHooks) CategoryCreateHook ¶
func (h *TaxonomyHooks) CategoryCreateHook(c fiber.Ctx, dto CategoryCreateDTO, model *Category) error
func (*TaxonomyHooks) CategoryDeleteHook ¶
func (h *TaxonomyHooks) CategoryDeleteHook(_ fiber.Ctx, _ any) error
func (*TaxonomyHooks) CategoryGetAllHook ¶
func (h *TaxonomyHooks) CategoryGetAllHook(_ fiber.Ctx, _ *[]query.Condition, _ *[]crud.OrderByClause) error
func (*TaxonomyHooks) CategoryGetByIDHook ¶
func (h *TaxonomyHooks) CategoryGetByIDHook(_ fiber.Ctx, _ any) error
func (*TaxonomyHooks) CategoryUpdateHook ¶
func (h *TaxonomyHooks) CategoryUpdateHook(c fiber.Ctx, dto CategoryUpdateDTO, model *Category) error
func (*TaxonomyHooks) TagCreateHook ¶
func (h *TaxonomyHooks) TagCreateHook(c fiber.Ctx, dto TagCreateDTO, model *Tag) error
func (*TaxonomyHooks) TagDeleteHook ¶
func (h *TaxonomyHooks) TagDeleteHook(_ fiber.Ctx, _ any) error
func (*TaxonomyHooks) TagGetAllHook ¶
func (h *TaxonomyHooks) TagGetAllHook(_ fiber.Ctx, _ *[]query.Condition, _ *[]crud.OrderByClause) error
func (*TaxonomyHooks) TagGetByIDHook ¶
func (h *TaxonomyHooks) TagGetByIDHook(_ fiber.Ctx, _ any) error
func (*TaxonomyHooks) TagUpdateHook ¶
func (h *TaxonomyHooks) TagUpdateHook(_ fiber.Ctx, dto TagUpdateDTO, model *Tag) error
type TaxonomyPlugin ¶
type TaxonomyPlugin struct {
// contains filtered or unexported fields
}
func (*TaxonomyPlugin) Dependencies ¶
func (p *TaxonomyPlugin) Dependencies() []string
func (*TaxonomyPlugin) GetOpenAPIResources ¶
func (p *TaxonomyPlugin) GetOpenAPIResources() []plugin.OpenAPIResource
func (*TaxonomyPlugin) GetService ¶ added in v0.2.4
func (p *TaxonomyPlugin) GetService() *TaxonomyService
func (*TaxonomyPlugin) Handler ¶
func (p *TaxonomyPlugin) Handler() fiber.Handler
func (*TaxonomyPlugin) Initialize ¶
func (p *TaxonomyPlugin) Initialize(config map[string]interface{}) error
func (*TaxonomyPlugin) MigrationDependencies ¶
func (p *TaxonomyPlugin) MigrationDependencies() []string
func (*TaxonomyPlugin) MigrationSource ¶
func (p *TaxonomyPlugin) MigrationSource() interface{}
func (*TaxonomyPlugin) Name ¶
func (p *TaxonomyPlugin) Name() string
func (*TaxonomyPlugin) SetupEndpoints ¶
func (p *TaxonomyPlugin) SetupEndpoints(router fiber.Router) error
type TaxonomyService ¶
type TaxonomyService struct {
// contains filtered or unexported fields
}
func NewTaxonomyService ¶
func NewTaxonomyService(db database.Database, config *Config) *TaxonomyService
func (*TaxonomyService) AttachCategory ¶
func (*TaxonomyService) BuildCategoryTree ¶
func (s *TaxonomyService) BuildCategoryTree(categories []Category) []*CategoryTreeNode
func (*TaxonomyService) DetachCategory ¶
func (*TaxonomyService) GetAllCategories ¶
func (s *TaxonomyService) GetAllCategories(ctx context.Context) ([]Category, error)
func (*TaxonomyService) GetCategoriesForResource ¶
func (s *TaxonomyService) GetCategoriesForResource(ctx context.Context, resource string, resourceID uuid.UUID) ([]Category, error)
GetCategoriesForResource returns the categories attached to a single resource. It delegates to the batch loader so both paths share one query shape.
func (*TaxonomyService) GetCategoriesForResources ¶ added in v0.6.0
func (s *TaxonomyService) GetCategoriesForResources(ctx context.Context, resource string, resourceIDs []uuid.UUID) (map[uuid.UUID][]Category, error)
GetCategoriesForResources loads categories for a batch of resources of the same type in a single query, keyed by resource id. This is the N+1 escape hatch for consumers that render categories across a page of resources: one round trip instead of one per resource.
func (*TaxonomyService) GetCategoryDepth ¶
GetCategoryDepth returns how many ancestors a category has. It loads the id→parent map in one query and walks it in memory instead of issuing a query per level, which turned the depth check into up to MaxDepth round trips. The map is read straight from the database (not the cache) so a parent created concurrently is always visible to the depth guard.
func (*TaxonomyService) GetResourceIDsByCategorySlug ¶ added in v0.2.4
func (*TaxonomyService) GetResourceIDsByTagSlug ¶ added in v0.2.4
func (*TaxonomyService) GetTagsForResource ¶
func (s *TaxonomyService) GetTagsForResource(ctx context.Context, resource string, resourceID uuid.UUID) ([]Tag, error)
GetTagsForResource returns the tags attached to a single resource, delegating to the batch loader.
func (*TaxonomyService) GetTagsForResources ¶ added in v0.6.0
func (s *TaxonomyService) GetTagsForResources(ctx context.Context, resource string, resourceIDs []uuid.UUID) (map[uuid.UUID][]Tag, error)
GetTagsForResources loads tags for a batch of resources of the same type in a single query, keyed by resource id.
func (*TaxonomyService) InvalidateCategoryCache ¶ added in v0.6.0
func (s *TaxonomyService) InvalidateCategoryCache()
InvalidateCategoryCache drops the memoized category set. It must be called after any committed create/update/delete of a category so the next read reloads fresh data.