Documentation
¶
Overview ¶
Package sectiontemplate provides domain models and data operations for section templates. Section templates are user-saved section configurations that can be reused across pages.
Index ¶
- Variables
- type CreateInput
- type ListFilter
- type ListResult
- type PostgresRepository
- func (r *PostgresRepository) Create(ctx context.Context, userID *uuid.UUID, input *CreateInput) (*SectionTemplate, error)
- func (r *PostgresRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (r *PostgresRepository) GetByID(ctx context.Context, id uuid.UUID) (*SectionTemplate, error)
- func (r *PostgresRepository) IncrementUsage(ctx context.Context, id uuid.UUID) error
- func (r *PostgresRepository) List(ctx context.Context, filter *ListFilter, limit, offset int) (*ListResult, error)
- func (r *PostgresRepository) Update(ctx context.Context, id uuid.UUID, input *UpdateInput) (*SectionTemplate, error)
- type Repository
- type SectionTemplate
- type Service
- func (s *Service) Create(ctx context.Context, userID *uuid.UUID, input *CreateInput) (*SectionTemplate, error)
- func (s *Service) Delete(ctx context.Context, id uuid.UUID) error
- func (s *Service) Get(ctx context.Context, id uuid.UUID) (*SectionTemplate, error)
- func (s *Service) List(ctx context.Context, filter *ListFilter, limit, offset int) (*ListResult, error)
- func (s *Service) RecordUsage(ctx context.Context, id uuid.UUID) error
- func (s *Service) Update(ctx context.Context, id uuid.UUID, input *UpdateInput) (*SectionTemplate, error)
- type UpdateInput
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var (
ErrTemplateNotFound = errors.New("section template not found")
)
Common errors.
Functions ¶
This section is empty.
Types ¶
type CreateInput ¶
type CreateInput struct {
Name string `json:"name"`
Description string `json:"description"`
SectionType string `json:"section_type"`
Content json.RawMessage `json:"content"`
Tags []string `json:"tags"`
}
CreateInput represents input for creating a new section template.
type ListFilter ¶
type ListFilter struct {
SectionType string `json:"section_type,omitempty"`
Search string `json:"search,omitempty"`
}
ListFilter represents filter options for listing section templates.
type ListResult ¶
type ListResult struct {
Items []SectionTemplate `json:"items"`
Total int `json:"total"`
}
ListResult represents a paginated list of section templates.
type PostgresRepository ¶
type PostgresRepository struct {
// contains filtered or unexported fields
}
PostgresRepository implements Repository using PostgreSQL.
func NewPostgresRepository ¶
func NewPostgresRepository(db *database.DB) *PostgresRepository
NewPostgresRepository creates a new PostgreSQL section template repository.
func (*PostgresRepository) Create ¶
func (r *PostgresRepository) Create(ctx context.Context, userID *uuid.UUID, input *CreateInput) (*SectionTemplate, error)
Create inserts a new section template.
func (*PostgresRepository) GetByID ¶
func (r *PostgresRepository) GetByID(ctx context.Context, id uuid.UUID) (*SectionTemplate, error)
GetByID retrieves a section template by ID. Used internally for existence checks.
func (*PostgresRepository) IncrementUsage ¶
IncrementUsage atomically increments the usage_count for a section template.
func (*PostgresRepository) List ¶
func (r *PostgresRepository) List(ctx context.Context, filter *ListFilter, limit, offset int) (*ListResult, error)
List retrieves section templates with optional filtering and offset pagination.
func (*PostgresRepository) Update ¶
func (r *PostgresRepository) Update(ctx context.Context, id uuid.UUID, input *UpdateInput) (*SectionTemplate, error)
Update changes a template's name, description and tags.
type Repository ¶
type Repository interface {
Create(ctx context.Context, userID *uuid.UUID, input *CreateInput) (*SectionTemplate, error)
GetByID(ctx context.Context, id uuid.UUID) (*SectionTemplate, error)
List(ctx context.Context, filter *ListFilter, limit, offset int) (*ListResult, error)
Update(ctx context.Context, id uuid.UUID, input *UpdateInput) (*SectionTemplate, error)
Delete(ctx context.Context, id uuid.UUID) error
IncrementUsage(ctx context.Context, id uuid.UUID) error
}
Repository defines the interface for section template data operations.
type SectionTemplate ¶
type SectionTemplate struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
SectionType string `json:"section_type"`
Content json.RawMessage `json:"content"`
Tags []string `json:"tags"`
UsageCount int `json:"usage_count"`
CreatedBy *uuid.UUID `json:"created_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
SectionTemplate represents a saved section configuration.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides business logic for section template management.
func NewService ¶
func NewService(repo Repository, logger *slog.Logger) *Service
NewService creates a new section template service.
func (*Service) Create ¶
func (s *Service) Create(ctx context.Context, userID *uuid.UUID, input *CreateInput) (*SectionTemplate, error)
Create creates a new section template after validating required fields.
func (*Service) List ¶
func (s *Service) List(ctx context.Context, filter *ListFilter, limit, offset int) (*ListResult, error)
List retrieves section templates with optional filtering and pagination.
func (*Service) RecordUsage ¶
RecordUsage increments the usage count for a template.
func (*Service) Update ¶
func (s *Service) Update(ctx context.Context, id uuid.UUID, input *UpdateInput) (*SectionTemplate, error)
Update renames a template and edits its description and tags.
type UpdateInput ¶
type UpdateInput struct {
Name string `json:"name"`
Description string `json:"description"`
Tags []string `json:"tags"`
}
UpdateInput represents the editable parts of a section template: its labels. The saved section content is changed by saving the section again.
type ValidationError ¶
ValidationError represents a field-level validation error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.