Help us shape the future of Go! Take the 2026 Go Developer Survey

sectiontemplate

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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) Delete

func (r *PostgresRepository) Delete(ctx context.Context, id uuid.UUID) error

Delete removes a section template by ID.

func (*PostgresRepository) GetByID

GetByID retrieves a section template by ID. Used internally for existence checks.

func (*PostgresRepository) IncrementUsage

func (r *PostgresRepository) IncrementUsage(ctx context.Context, id uuid.UUID) error

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

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) Delete

func (s *Service) Delete(ctx context.Context, id uuid.UUID) error

Delete removes a section template by ID.

func (*Service) Get

func (s *Service) Get(ctx context.Context, id uuid.UUID) (*SectionTemplate, error)

Get returns one section template.

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

func (s *Service) RecordUsage(ctx context.Context, id uuid.UUID) error

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

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ValidationError represents a field-level validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface.

Jump to

Keyboard shortcuts

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