Documentation
¶
Index ¶
- Constants
- Variables
- func DeriveContentTypeSlug(ct *ContentType) string
- func ExtractEmbeddedBlocks(payload map[string]any) ([]map[string]any, bool)
- func MergeEmbeddedBlocks(payload map[string]any, blocks []map[string]any) map[string]any
- func NewContentRepository(db *bun.DB) repository.Repository[*Content]
- func NewContentTranslationRepository(db *bun.DB) repository.Repository[*ContentTranslation]
- func NewContentTypeRepository(db *bun.DB) repository.Repository[*ContentType]
- func NewContentVersionRepository(db *bun.DB) repository.Repository[*ContentVersion]
- func NewLocaleRepository(db *bun.DB) repository.Repository[*Locale]
- func NormalizeLocale(code string) string
- func SanitizeEmbeddedBlocks(payload map[string]any) map[string]any
- type BunContentRepository
- func (r *BunContentRepository) Create(ctx context.Context, record *Content) (*Content, error)
- func (r *BunContentRepository) CreateVersion(ctx context.Context, version *ContentVersion) (*ContentVersion, error)
- func (r *BunContentRepository) Delete(ctx context.Context, id uuid.UUID, hardDelete bool) error
- func (r *BunContentRepository) GetByID(ctx context.Context, id uuid.UUID) (*Content, error)
- func (r *BunContentRepository) GetBySlug(ctx context.Context, slug string) (*Content, error)
- func (r *BunContentRepository) GetLatestVersion(ctx context.Context, contentID uuid.UUID) (*ContentVersion, error)
- func (r *BunContentRepository) GetVersion(ctx context.Context, contentID uuid.UUID, number int) (*ContentVersion, error)
- func (r *BunContentRepository) List(ctx context.Context) ([]*Content, error)
- func (r *BunContentRepository) ListTranslations(ctx context.Context, contentID uuid.UUID) ([]*ContentTranslation, error)
- func (r *BunContentRepository) ListVersions(ctx context.Context, contentID uuid.UUID) ([]*ContentVersion, error)
- func (r *BunContentRepository) ReplaceTranslations(ctx context.Context, contentID uuid.UUID, translations []*ContentTranslation) error
- func (r *BunContentRepository) Update(ctx context.Context, record *Content) (*Content, error)
- func (r *BunContentRepository) UpdateVersion(ctx context.Context, version *ContentVersion) (*ContentVersion, error)
- type BunContentTypeRepository
- func (r *BunContentTypeRepository) Create(ctx context.Context, record *ContentType) (*ContentType, error)
- func (r *BunContentTypeRepository) Delete(ctx context.Context, id uuid.UUID, _ bool) error
- func (r *BunContentTypeRepository) GetByID(ctx context.Context, id uuid.UUID) (*ContentType, error)
- func (r *BunContentTypeRepository) GetBySlug(ctx context.Context, slug string) (*ContentType, error)
- func (r *BunContentTypeRepository) List(ctx context.Context) ([]*ContentType, error)
- func (r *BunContentTypeRepository) Search(ctx context.Context, query string) ([]*ContentType, error)
- func (r *BunContentTypeRepository) Update(ctx context.Context, record *ContentType) (*ContentType, error)
- type BunLocaleRepository
- type Content
- type ContentPreview
- type ContentRepository
- type ContentTranslation
- type ContentTranslationInput
- type ContentTranslationReader
- type ContentType
- type ContentTypeOption
- type ContentTypeRepository
- type ContentTypeService
- type ContentVersion
- type ContentVersionSnapshot
- type ContentVersionTranslationSnapshot
- type CreateContentDraftRequest
- type CreateContentRequest
- type CreateContentTypeRequest
- type DeleteContentRequest
- type DeleteContentTranslationRequest
- type DeleteContentTypeRequest
- type EmbeddedBlockConflict
- type EmbeddedBlockValidationError
- type EmbeddedBlockValidationIssue
- type EmbeddedBlockValidationMode
- type EmbeddedBlocksResolver
- type IDGenerator
- type Locale
- type LocaleRepository
- type MemoryContentRepository
- func (m *MemoryContentRepository) Create(_ context.Context, record *Content) (*Content, error)
- func (m *MemoryContentRepository) CreateVersion(_ context.Context, version *ContentVersion) (*ContentVersion, error)
- func (m *MemoryContentRepository) Delete(_ context.Context, id uuid.UUID, hardDelete bool) error
- func (m *MemoryContentRepository) GetByID(_ context.Context, id uuid.UUID) (*Content, error)
- func (m *MemoryContentRepository) GetBySlug(_ context.Context, slug string) (*Content, error)
- func (m *MemoryContentRepository) GetLatestVersion(_ context.Context, contentID uuid.UUID) (*ContentVersion, error)
- func (m *MemoryContentRepository) GetVersion(_ context.Context, contentID uuid.UUID, number int) (*ContentVersion, error)
- func (m *MemoryContentRepository) List(_ context.Context) ([]*Content, error)
- func (m *MemoryContentRepository) ListTranslations(_ context.Context, contentID uuid.UUID) ([]*ContentTranslation, error)
- func (m *MemoryContentRepository) ListVersions(_ context.Context, contentID uuid.UUID) ([]*ContentVersion, error)
- func (m *MemoryContentRepository) ReplaceTranslations(_ context.Context, contentID uuid.UUID, translations []*ContentTranslation) error
- func (m *MemoryContentRepository) Update(_ context.Context, record *Content) (*Content, error)
- func (m *MemoryContentRepository) UpdateVersion(_ context.Context, version *ContentVersion) (*ContentVersion, error)
- type MemoryContentTypeRepository
- func (m *MemoryContentTypeRepository) Create(ctx context.Context, ct *ContentType) (*ContentType, error)
- func (m *MemoryContentTypeRepository) Delete(_ context.Context, id uuid.UUID, _ bool) error
- func (m *MemoryContentTypeRepository) GetByID(_ context.Context, id uuid.UUID) (*ContentType, error)
- func (m *MemoryContentTypeRepository) GetBySlug(_ context.Context, slug string) (*ContentType, error)
- func (m *MemoryContentTypeRepository) List(_ context.Context) ([]*ContentType, error)
- func (m *MemoryContentTypeRepository) Put(ct *ContentType) error
- func (m *MemoryContentTypeRepository) Search(ctx context.Context, query string) ([]*ContentType, error)
- func (m *MemoryContentTypeRepository) Update(ctx context.Context, ct *ContentType) (*ContentType, error)
- type MemoryLocaleRepository
- type NotFoundError
- type PreviewContentDraftRequest
- type PublishContentDraftRequest
- type RestoreContentVersionRequest
- type ScheduleContentRequest
- type Service
- type ServiceOption
- func WithActivityEmitter(emitter *activity.Emitter) ServiceOption
- func WithClock(clock func() time.Time) ServiceOption
- func WithDefaultLocale(locale string, required bool) ServiceOption
- func WithEmbeddedBlocksResolver(resolver EmbeddedBlocksResolver) ServiceOption
- func WithIDGenerator(generator IDGenerator) ServiceOption
- func WithLogger(logger interfaces.Logger) ServiceOption
- func WithRequireTranslations(required bool) ServiceOption
- func WithScheduler(scheduler interfaces.Scheduler) ServiceOption
- func WithSchedulingEnabled(enabled bool) ServiceOption
- func WithSchemaMigrator(migrator *cmsschema.Migrator) ServiceOption
- func WithSlugNormalizer(normalizer slug.Normalizer) ServiceOption
- func WithTranslationState(state *translationconfig.State) ServiceOption
- func WithTranslationsEnabled(enabled bool) ServiceOption
- func WithVersionRetentionLimit(limit int) ServiceOption
- func WithVersioningEnabled(enabled bool) ServiceOption
- type UpdateContentRequest
- type UpdateContentTranslationRequest
- type UpdateContentTypeRequest
Constants ¶
const ( // EmbeddedBlocksKey is the payload key holding embedded blocks. EmbeddedBlocksKey = "blocks" // EmbeddedBlockTypeKey identifies the block type discriminator. EmbeddedBlockTypeKey = "_type" // EmbeddedBlockSchemaKey tracks the block schema version. EmbeddedBlockSchemaKey = "_schema" // EmbeddedBlockMetaKey stores system metadata alongside embedded blocks. EmbeddedBlockMetaKey = "_cms" )
const ( ConflictEmbeddedMissing = "embedded_missing" ConflictLegacyMissing = "legacy_missing" ConflictTypeMismatch = "type_mismatch" ConflictSchemaMismatch = "schema_mismatch" ConflictContentMismatch = "content_mismatch" ConflictConfigMismatch = "configuration_mismatch" ConflictAttrsMismatch = "attribute_overrides_mismatch" ConflictMediaMismatch = "media_bindings_mismatch" )
Variables ¶
var ( ErrContentTypeNameRequired = errors.New("content type: name is required") ErrContentTypeSchemaRequired = errors.New("content type: schema is required") ErrContentTypeIDRequired = errors.New("content type: id required") ErrContentTypeSlugInvalid = errors.New("content type: slug contains invalid characters") ErrContentTypeSchemaVersion = errors.New("content type: schema version invalid") )
var ( ErrContentTypeSlugRequired = errors.New("content type: slug is required") ErrContentTypeSlugExists = errors.New("content type: slug already exists") )
var ( ErrContentTypeRequired = errors.New("content: content type does not exist") ErrSlugRequired = errors.New("content: slug is required") ErrSlugInvalid = errors.New("content: slug contains invalid characters") ErrSlugExists = errors.New("content: slug already exists") ErrNoTranslations = errors.New("content: at least one translation is required") ErrDefaultLocaleRequired = errors.New("content: default locale translation is required") ErrDuplicateLocale = errors.New("content: duplicate locale provided") ErrUnknownLocale = errors.New("content: unknown locale") ErrContentSchemaInvalid = errors.New("content: schema validation failed") ErrContentSoftDeleteUnsupported = errors.New("content: soft delete not supported") ErrContentIDRequired = errors.New("content: content id required") ErrVersioningDisabled = errors.New("content: versioning feature disabled") ErrContentVersionRequired = errors.New("content: version identifier required") ErrContentVersionConflict = errors.New("content: base version mismatch") ErrContentVersionAlreadyPublished = errors.New("content: version already published") ErrContentVersionRetentionExceeded = errors.New("content: version retention limit reached") ErrSchedulingDisabled = errors.New("content: scheduling feature disabled") ErrScheduleWindowInvalid = errors.New("content: publish_at must be before unpublish_at") ErrScheduleTimestampInvalid = errors.New("content: schedule timestamp is invalid") ErrContentTranslationsDisabled = errors.New("content: translations feature disabled") ErrContentTranslationNotFound = errors.New("content: translation not found") ErrContentSchemaMigrationRequired = errors.New("content: schema migration required") ErrContentTranslationLookupUnsupported = errors.New("content: translation lookup unsupported") ErrEmbeddedBlocksResolverMissing = errors.New("content: embedded blocks resolver not configured") )
var ContentVersionSnapshotSchema = cmscontent.ContentVersionSnapshotSchema
Functions ¶
func DeriveContentTypeSlug ¶ added in v0.20.0
func DeriveContentTypeSlug(ct *ContentType) string
DeriveContentTypeSlug derives a deterministic slug for backfill/seed flows. Prefers explicit slug, then schema metadata, then normalized name.
func ExtractEmbeddedBlocks ¶ added in v0.21.0
ExtractEmbeddedBlocks returns embedded block payloads from a translation content map.
func MergeEmbeddedBlocks ¶ added in v0.21.0
MergeEmbeddedBlocks applies a blocks slice to the content payload, returning a copy.
func NewContentRepository ¶
func NewContentRepository(db *bun.DB) repository.Repository[*Content]
func NewContentTranslationRepository ¶
func NewContentTranslationRepository(db *bun.DB) repository.Repository[*ContentTranslation]
func NewContentTypeRepository ¶
func NewContentTypeRepository(db *bun.DB) repository.Repository[*ContentType]
func NewContentVersionRepository ¶
func NewContentVersionRepository(db *bun.DB) repository.Repository[*ContentVersion]
NewContentVersionRepository creates a repository for ContentVersion entities.
func NewLocaleRepository ¶
func NewLocaleRepository(db *bun.DB) repository.Repository[*Locale]
func NormalizeLocale ¶ added in v0.21.0
NormalizeLocale trims and lowercases locale codes for comparison.
Types ¶
type BunContentRepository ¶
type BunContentRepository struct {
// contains filtered or unexported fields
}
func NewBunContentRepository ¶
func NewBunContentRepository(db *bun.DB) *BunContentRepository
func NewBunContentRepositoryWithCache ¶
func NewBunContentRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, keySerializer cache.KeySerializer) *BunContentRepository
func (*BunContentRepository) CreateVersion ¶
func (r *BunContentRepository) CreateVersion(ctx context.Context, version *ContentVersion) (*ContentVersion, error)
func (*BunContentRepository) GetLatestVersion ¶
func (r *BunContentRepository) GetLatestVersion(ctx context.Context, contentID uuid.UUID) (*ContentVersion, error)
func (*BunContentRepository) GetVersion ¶
func (r *BunContentRepository) GetVersion(ctx context.Context, contentID uuid.UUID, number int) (*ContentVersion, error)
func (*BunContentRepository) List ¶
func (r *BunContentRepository) List(ctx context.Context) ([]*Content, error)
func (*BunContentRepository) ListTranslations ¶ added in v0.21.0
func (r *BunContentRepository) ListTranslations(ctx context.Context, contentID uuid.UUID) ([]*ContentTranslation, error)
ListTranslations returns translations for a content record.
func (*BunContentRepository) ListVersions ¶
func (r *BunContentRepository) ListVersions(ctx context.Context, contentID uuid.UUID) ([]*ContentVersion, error)
func (*BunContentRepository) ReplaceTranslations ¶
func (r *BunContentRepository) ReplaceTranslations(ctx context.Context, contentID uuid.UUID, translations []*ContentTranslation) error
func (*BunContentRepository) UpdateVersion ¶
func (r *BunContentRepository) UpdateVersion(ctx context.Context, version *ContentVersion) (*ContentVersion, error)
type BunContentTypeRepository ¶
type BunContentTypeRepository struct {
// contains filtered or unexported fields
}
func NewBunContentTypeRepository ¶
func NewBunContentTypeRepository(db *bun.DB) *BunContentTypeRepository
func NewBunContentTypeRepositoryWithCache ¶
func NewBunContentTypeRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, keySerializer cache.KeySerializer) *BunContentTypeRepository
func (*BunContentTypeRepository) Create ¶ added in v0.20.0
func (r *BunContentTypeRepository) Create(ctx context.Context, record *ContentType) (*ContentType, error)
func (*BunContentTypeRepository) GetByID ¶
func (r *BunContentTypeRepository) GetByID(ctx context.Context, id uuid.UUID) (*ContentType, error)
func (*BunContentTypeRepository) GetBySlug ¶ added in v0.20.0
func (r *BunContentTypeRepository) GetBySlug(ctx context.Context, slug string) (*ContentType, error)
func (*BunContentTypeRepository) List ¶ added in v0.20.0
func (r *BunContentTypeRepository) List(ctx context.Context) ([]*ContentType, error)
func (*BunContentTypeRepository) Search ¶ added in v0.20.0
func (r *BunContentTypeRepository) Search(ctx context.Context, query string) ([]*ContentType, error)
func (*BunContentTypeRepository) Update ¶ added in v0.20.0
func (r *BunContentTypeRepository) Update(ctx context.Context, record *ContentType) (*ContentType, error)
type BunLocaleRepository ¶
type BunLocaleRepository struct {
// contains filtered or unexported fields
}
func NewBunLocaleRepository ¶
func NewBunLocaleRepository(db *bun.DB) *BunLocaleRepository
func NewBunLocaleRepositoryWithCache ¶
func NewBunLocaleRepositoryWithCache(db *bun.DB, cacheService cache.CacheService, keySerializer cache.KeySerializer) *BunLocaleRepository
NewBunLocaleRepositoryWithCache constructs a LocaleRepository with optional caching.
type Content ¶
type Content = cmscontent.Content
type ContentPreview ¶ added in v0.21.0
type ContentPreview struct {
Content *Content
Version *ContentVersion
}
ContentPreview bundles a preview snapshot with the derived content record.
type ContentRepository ¶
type ContentRepository interface {
Create(ctx context.Context, record *Content) (*Content, error)
GetByID(ctx context.Context, id uuid.UUID) (*Content, error)
GetBySlug(ctx context.Context, slug string) (*Content, error)
List(ctx context.Context) ([]*Content, error)
Update(ctx context.Context, record *Content) (*Content, error)
ReplaceTranslations(ctx context.Context, contentID uuid.UUID, translations []*ContentTranslation) error
Delete(ctx context.Context, id uuid.UUID, hardDelete bool) error
CreateVersion(ctx context.Context, version *ContentVersion) (*ContentVersion, error)
ListVersions(ctx context.Context, contentID uuid.UUID) ([]*ContentVersion, error)
GetVersion(ctx context.Context, contentID uuid.UUID, number int) (*ContentVersion, error)
GetLatestVersion(ctx context.Context, contentID uuid.UUID) (*ContentVersion, error)
UpdateVersion(ctx context.Context, version *ContentVersion) (*ContentVersion, error)
}
ContentRepository abstracts storage operations for content entities.
type ContentTranslation ¶
type ContentTranslation = cmscontent.ContentTranslation
type ContentTranslationInput ¶
type ContentTranslationInput struct {
Locale string
Title string
Summary *string
Content map[string]any
Blocks []map[string]any
}
ContentTranslationInput represents localized fields supplied during create.
type ContentTranslationReader ¶ added in v0.21.0
type ContentTranslationReader interface {
ListTranslations(ctx context.Context, contentID uuid.UUID) ([]*ContentTranslation, error)
}
ContentTranslationReader exposes translation lookups without replacing the core repository interface.
type ContentType ¶
type ContentType = cmscontent.ContentType
type ContentTypeOption ¶ added in v0.20.0
type ContentTypeOption func(*contentTypeService)
ContentTypeOption mutates the content type service.
func WithContentTypeClock ¶ added in v0.20.0
func WithContentTypeClock(clock func() time.Time) ContentTypeOption
WithContentTypeClock overrides the clock used by the service.
func WithContentTypeIDGenerator ¶ added in v0.20.0
func WithContentTypeIDGenerator(generator IDGenerator) ContentTypeOption
WithContentTypeIDGenerator overrides the ID generator used by the service.
func WithContentTypeSlugNormalizer ¶ added in v0.20.0
func WithContentTypeSlugNormalizer(normalizer slug.Normalizer) ContentTypeOption
WithContentTypeSlugNormalizer overrides the slug normalizer used by the service.
type ContentTypeRepository ¶
type ContentTypeRepository interface {
Create(ctx context.Context, record *ContentType) (*ContentType, error)
GetByID(ctx context.Context, id uuid.UUID) (*ContentType, error)
GetBySlug(ctx context.Context, slug string) (*ContentType, error)
List(ctx context.Context) ([]*ContentType, error)
Search(ctx context.Context, query string) ([]*ContentType, error)
Update(ctx context.Context, record *ContentType) (*ContentType, error)
Delete(ctx context.Context, id uuid.UUID, hardDelete bool) error
}
ContentTypeRepository resolves content types.
type ContentTypeService ¶ added in v0.20.0
type ContentTypeService interface {
Create(ctx context.Context, req CreateContentTypeRequest) (*ContentType, error)
Update(ctx context.Context, req UpdateContentTypeRequest) (*ContentType, error)
Delete(ctx context.Context, req DeleteContentTypeRequest) error
Get(ctx context.Context, id uuid.UUID) (*ContentType, error)
GetBySlug(ctx context.Context, slug string) (*ContentType, error)
List(ctx context.Context) ([]*ContentType, error)
Search(ctx context.Context, query string) ([]*ContentType, error)
}
ContentTypeService provides CRUD operations for content types.
func NewContentTypeService ¶ added in v0.20.0
func NewContentTypeService(repo ContentTypeRepository, opts ...ContentTypeOption) ContentTypeService
NewContentTypeService constructs a content type service.
type ContentVersion ¶
type ContentVersion = cmscontent.ContentVersion
type ContentVersionSnapshot ¶
type ContentVersionSnapshot = cmscontent.ContentVersionSnapshot
type ContentVersionTranslationSnapshot ¶
type ContentVersionTranslationSnapshot = cmscontent.ContentVersionTranslationSnapshot
type CreateContentDraftRequest ¶
type CreateContentDraftRequest struct {
ContentID uuid.UUID
Snapshot ContentVersionSnapshot
CreatedBy uuid.UUID
UpdatedBy uuid.UUID
BaseVersion *int
}
CreateContentDraftRequest captures the payload needed to record a draft snapshot.
type CreateContentRequest ¶
type CreateContentRequest struct {
ContentTypeID uuid.UUID
Slug string
Status string
CreatedBy uuid.UUID
UpdatedBy uuid.UUID
Translations []ContentTranslationInput
AllowMissingTranslations bool
}
CreateContentRequest captures the information required to create content.
type CreateContentTypeRequest ¶ added in v0.20.0
type CreateContentTypeRequest struct {
Name string
Slug string
Description *string
Schema map[string]any
Capabilities map[string]any
Icon *string
}
CreateContentTypeRequest captures required fields to create a content type.
type DeleteContentRequest ¶
DeleteContentRequest captures the information required to remove a content entry. When HardDelete is false the record should be soft-deleted if the implementation supports it; otherwise the request should fail fast.
type DeleteContentTranslationRequest ¶ added in v0.2.0
type DeleteContentTranslationRequest struct {
ContentID uuid.UUID
Locale string
DeletedBy uuid.UUID
}
DeleteContentTranslationRequest captures the payload required to drop a translation.
type DeleteContentTypeRequest ¶ added in v0.20.0
DeleteContentTypeRequest captures details required to delete a content type.
type EmbeddedBlockConflict ¶ added in v0.21.0
type EmbeddedBlockConflict struct {
ContentID uuid.UUID `json:"content_id"`
PageID uuid.UUID `json:"page_id"`
Locale string `json:"locale,omitempty"`
Region string `json:"region,omitempty"`
Index int `json:"index,omitempty"`
Issue string `json:"issue"`
EmbeddedType string `json:"embedded_type,omitempty"`
LegacyType string `json:"legacy_type,omitempty"`
EmbeddedSchema string `json:"embedded_schema,omitempty"`
LegacySchema string `json:"legacy_schema,omitempty"`
LegacyInstanceID uuid.UUID `json:"legacy_instance_id,omitempty"`
Details map[string]any `json:"details,omitempty"`
}
EmbeddedBlockConflict describes mismatches between embedded and legacy block payloads.
type EmbeddedBlockValidationError ¶ added in v0.21.0
type EmbeddedBlockValidationError struct {
Mode EmbeddedBlockValidationMode
Issues []EmbeddedBlockValidationIssue
}
EmbeddedBlockValidationError aggregates embedded block validation failures.
func (*EmbeddedBlockValidationError) Error ¶ added in v0.21.0
func (e *EmbeddedBlockValidationError) Error() string
type EmbeddedBlockValidationIssue ¶ added in v0.21.0
type EmbeddedBlockValidationIssue struct {
Locale string `json:"locale,omitempty"`
Index int `json:"index,omitempty"`
Type string `json:"type,omitempty"`
Schema string `json:"schema,omitempty"`
Field string `json:"field,omitempty"`
Message string `json:"message,omitempty"`
}
EmbeddedBlockValidationIssue captures validation failures with block context.
type EmbeddedBlockValidationMode ¶ added in v0.21.0
type EmbeddedBlockValidationMode string
EmbeddedBlockValidationMode controls how strict validation should be.
const ( EmbeddedBlockValidationDraft EmbeddedBlockValidationMode = "draft" EmbeddedBlockValidationStrict EmbeddedBlockValidationMode = "strict" )
type EmbeddedBlocksResolver ¶ added in v0.21.0
type EmbeddedBlocksResolver interface {
SyncEmbeddedBlocks(ctx context.Context, contentID uuid.UUID, translations []ContentTranslationInput, actor uuid.UUID) error
MergeLegacyBlocks(ctx context.Context, record *Content) error
MigrateEmbeddedBlocks(ctx context.Context, locale string, blocks []map[string]any) ([]map[string]any, error)
ValidateEmbeddedBlocks(ctx context.Context, locale string, blocks []map[string]any, mode EmbeddedBlockValidationMode) error
ValidateBlockAvailability(ctx context.Context, contentType string, availability cmsschema.BlockAvailability, blocks []map[string]any) error
}
EmbeddedBlocksResolver bridges embedded blocks to legacy block instances.
type IDGenerator ¶
IDGenerator returns the identifier used for newly created records.
type Locale ¶
type Locale = cmscontent.Locale
type LocaleRepository ¶
LocaleRepository resolves locales by code.
type MemoryContentRepository ¶
type MemoryContentRepository struct {
// contains filtered or unexported fields
}
MemoryContentRepository is an "in memory" implementation for scaffolding and tests.
func NewMemoryContentRepository ¶
func NewMemoryContentRepository() *MemoryContentRepository
NewMemoryContentRepository creates an empty "in memory" content repository.
func (*MemoryContentRepository) CreateVersion ¶
func (m *MemoryContentRepository) CreateVersion(_ context.Context, version *ContentVersion) (*ContentVersion, error)
CreateVersion appends a new version snapshot for the supplied content entity.
func (*MemoryContentRepository) Delete ¶
Delete removes the content record and its associated versions when hard delete is requested.
func (*MemoryContentRepository) GetBySlug ¶
GetBySlug retrieves content by slug, returning NotFoundError when absent.
func (*MemoryContentRepository) GetLatestVersion ¶
func (m *MemoryContentRepository) GetLatestVersion(_ context.Context, contentID uuid.UUID) (*ContentVersion, error)
GetLatestVersion retrieves the most recent version for a content entity.
func (*MemoryContentRepository) GetVersion ¶
func (m *MemoryContentRepository) GetVersion(_ context.Context, contentID uuid.UUID, number int) (*ContentVersion, error)
GetVersion retrieves a specific content version by number.
func (*MemoryContentRepository) List ¶
func (m *MemoryContentRepository) List(_ context.Context) ([]*Content, error)
List returns all content entries.
func (*MemoryContentRepository) ListTranslations ¶ added in v0.21.0
func (m *MemoryContentRepository) ListTranslations(_ context.Context, contentID uuid.UUID) ([]*ContentTranslation, error)
ListTranslations returns stored translations for a content entry.
func (*MemoryContentRepository) ListVersions ¶
func (m *MemoryContentRepository) ListVersions(_ context.Context, contentID uuid.UUID) ([]*ContentVersion, error)
ListVersions returns every stored version for a content entity.
func (*MemoryContentRepository) ReplaceTranslations ¶
func (m *MemoryContentRepository) ReplaceTranslations(_ context.Context, contentID uuid.UUID, translations []*ContentTranslation) error
ReplaceTranslations swaps the translations associated with a content record.
func (*MemoryContentRepository) UpdateVersion ¶
func (m *MemoryContentRepository) UpdateVersion(_ context.Context, version *ContentVersion) (*ContentVersion, error)
UpdateVersion mutates metadata for a stored content version.
type MemoryContentTypeRepository ¶
type MemoryContentTypeRepository struct {
// contains filtered or unexported fields
}
MemoryContentTypeRepository stores content types "in memory".
func NewMemoryContentTypeRepository ¶
func NewMemoryContentTypeRepository() *MemoryContentTypeRepository
NewMemoryContentTypeRepository constructs the repository.
func (*MemoryContentTypeRepository) Create ¶ added in v0.20.0
func (m *MemoryContentTypeRepository) Create(ctx context.Context, ct *ContentType) (*ContentType, error)
Create inserts a content type record.
func (*MemoryContentTypeRepository) GetByID ¶
func (m *MemoryContentTypeRepository) GetByID(_ context.Context, id uuid.UUID) (*ContentType, error)
GetByID fetches a content type.
func (*MemoryContentTypeRepository) GetBySlug ¶ added in v0.20.0
func (m *MemoryContentTypeRepository) GetBySlug(_ context.Context, slug string) (*ContentType, error)
GetBySlug fetches a content type by slug.
func (*MemoryContentTypeRepository) List ¶ added in v0.20.0
func (m *MemoryContentTypeRepository) List(_ context.Context) ([]*ContentType, error)
List returns all content types.
func (*MemoryContentTypeRepository) Put ¶
func (m *MemoryContentTypeRepository) Put(ct *ContentType) error
Put inserts or replaces a content type.
func (*MemoryContentTypeRepository) Search ¶ added in v0.20.0
func (m *MemoryContentTypeRepository) Search(ctx context.Context, query string) ([]*ContentType, error)
Search returns content types whose name or slug contains the query.
func (*MemoryContentTypeRepository) Update ¶ added in v0.20.0
func (m *MemoryContentTypeRepository) Update(ctx context.Context, ct *ContentType) (*ContentType, error)
Update updates an existing content type.
type MemoryLocaleRepository ¶
type MemoryLocaleRepository struct {
// contains filtered or unexported fields
}
MemoryLocaleRepository stores locales by code.
func NewMemoryLocaleRepository ¶
func NewMemoryLocaleRepository() *MemoryLocaleRepository
NewMemoryLocaleRepository constructs the repository.
func (*MemoryLocaleRepository) Count ¶ added in v0.16.0
func (m *MemoryLocaleRepository) Count() int
Count returns the number of locales stored in memory.
func (*MemoryLocaleRepository) Put ¶
func (m *MemoryLocaleRepository) Put(locale *Locale)
Put inserts or replaces a locale.
type NotFoundError ¶
NotFoundError represents missing records from repository lookups.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type PreviewContentDraftRequest ¶ added in v0.21.0
PreviewContentDraftRequest captures the information required to preview a content draft.
type PublishContentDraftRequest ¶
type PublishContentDraftRequest struct {
ContentID uuid.UUID
Version int
PublishedBy uuid.UUID
PublishedAt *time.Time
}
PublishContentDraftRequest captures the information required to publish a content draft.
type RestoreContentVersionRequest ¶
RestoreContentVersionRequest captures the request to restore a prior content version.
type ScheduleContentRequest ¶
type ScheduleContentRequest struct {
ContentID uuid.UUID
PublishAt *time.Time
UnpublishAt *time.Time
ScheduledBy uuid.UUID
}
ScheduleContentRequest captures details to schedule publish/unpublish events.
type Service ¶
type Service interface {
Create(ctx context.Context, req CreateContentRequest) (*Content, error)
Get(ctx context.Context, id uuid.UUID) (*Content, error)
List(ctx context.Context) ([]*Content, error)
Update(ctx context.Context, req UpdateContentRequest) (*Content, error)
Delete(ctx context.Context, req DeleteContentRequest) error
UpdateTranslation(ctx context.Context, req UpdateContentTranslationRequest) (*ContentTranslation, error)
DeleteTranslation(ctx context.Context, req DeleteContentTranslationRequest) error
Schedule(ctx context.Context, req ScheduleContentRequest) (*Content, error)
CreateDraft(ctx context.Context, req CreateContentDraftRequest) (*ContentVersion, error)
PublishDraft(ctx context.Context, req PublishContentDraftRequest) (*ContentVersion, error)
PreviewDraft(ctx context.Context, req PreviewContentDraftRequest) (*ContentPreview, error)
ListVersions(ctx context.Context, contentID uuid.UUID) ([]*ContentVersion, error)
RestoreVersion(ctx context.Context, req RestoreContentVersionRequest) (*ContentVersion, error)
}
Service exposes content management use cases.
func NewService ¶
func NewService(contents ContentRepository, types ContentTypeRepository, locales LocaleRepository, opts ...ServiceOption) Service
NewService constructs a content service with the required dependencies.
type ServiceOption ¶
type ServiceOption func(*service)
ServiceOption configures the service at construction time.
func WithActivityEmitter ¶ added in v0.5.0
func WithActivityEmitter(emitter *activity.Emitter) ServiceOption
WithActivityEmitter wires the activity emitter used for activity records.
func WithClock ¶
func WithClock(clock func() time.Time) ServiceOption
WithClock overrides the clock used to stamp records.
func WithDefaultLocale ¶ added in v0.20.0
func WithDefaultLocale(locale string, required bool) ServiceOption
WithDefaultLocale sets the locale required for default fallback handling.
func WithEmbeddedBlocksResolver ¶ added in v0.21.0
func WithEmbeddedBlocksResolver(resolver EmbeddedBlocksResolver) ServiceOption
WithEmbeddedBlocksResolver wires the embedded blocks bridge (dual-write + fallback).
func WithIDGenerator ¶
func WithIDGenerator(generator IDGenerator) ServiceOption
WithIDGenerator overrides the generator used to create identifiers.
func WithLogger ¶
func WithLogger(logger interfaces.Logger) ServiceOption
WithLogger assigns the logger used by the service. When omitted, a no-op logger is used.
func WithRequireTranslations ¶ added in v0.2.0
func WithRequireTranslations(required bool) ServiceOption
WithRequireTranslations controls whether translations are mandatory.
func WithScheduler ¶
func WithScheduler(scheduler interfaces.Scheduler) ServiceOption
WithScheduler overrides the scheduler used to register publish/unpublish jobs.
func WithSchedulingEnabled ¶
func WithSchedulingEnabled(enabled bool) ServiceOption
WithSchedulingEnabled toggles scheduling-related workflows.
func WithSchemaMigrator ¶ added in v0.21.0
func WithSchemaMigrator(migrator *cmsschema.Migrator) ServiceOption
WithSchemaMigrator configures schema migrations for publish-time upgrades.
func WithSlugNormalizer ¶ added in v0.20.0
func WithSlugNormalizer(normalizer slug.Normalizer) ServiceOption
WithSlugNormalizer overrides the slug normalizer used by the service.
func WithTranslationState ¶ added in v0.16.0
func WithTranslationState(state *translationconfig.State) ServiceOption
WithTranslationState wires a shared, runtime-configurable translation state.
func WithTranslationsEnabled ¶ added in v0.2.0
func WithTranslationsEnabled(enabled bool) ServiceOption
WithTranslationsEnabled toggles translation handling.
func WithVersionRetentionLimit ¶
func WithVersionRetentionLimit(limit int) ServiceOption
WithVersionRetentionLimit constrains how many versions are retained per content entity.
func WithVersioningEnabled ¶
func WithVersioningEnabled(enabled bool) ServiceOption
WithVersioningEnabled toggles the versioning workflow for the service.
type UpdateContentRequest ¶
type UpdateContentRequest struct {
ID uuid.UUID
Status string
UpdatedBy uuid.UUID
Translations []ContentTranslationInput
Metadata map[string]any
AllowMissingTranslations bool
}
UpdateContentRequest captures mutable fields for an existing content entry. Slug and content type remain immutable and are inferred from the existing record.
type UpdateContentTranslationRequest ¶ added in v0.2.0
type UpdateContentTranslationRequest struct {
ContentID uuid.UUID
Locale string
Title string
Summary *string
Content map[string]any
Blocks []map[string]any
UpdatedBy uuid.UUID
}
UpdateContentTranslationRequest captures the payload required to mutate a single translation.