service

package
v0.0.11 Latest Latest
Warning

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

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

Documentation

Overview

Package service implements the business logic layer for the CMS plugin.

Package service implements the business logic layer for the CMS plugin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidationResultToMap

func ValidationResultToMap(result *core.ValidationResult) map[string]string

ValidationResultToMap converts validation result to error map for API responses

Types

type ComponentSchemaService

type ComponentSchemaService struct {
	// contains filtered or unexported fields
}

ComponentSchemaService handles component schema business logic

func NewComponentSchemaService

NewComponentSchemaService creates a new component schema service

func (*ComponentSchemaService) Create

Create creates a new component schema

func (*ComponentSchemaService) Delete

func (s *ComponentSchemaService) Delete(ctx context.Context, id xid.ID) error

Delete deletes a component schema

func (*ComponentSchemaService) GetByID

GetByID retrieves a component schema by ID

func (*ComponentSchemaService) GetByName

GetBySlug retrieves a component schema by slug

func (*ComponentSchemaService) GetEffectiveFields

func (s *ComponentSchemaService) GetEffectiveFields(ctx context.Context, field *core.ContentFieldDTO) ([]core.NestedFieldDefDTO, error)

GetEffectiveFields returns the effective nested fields for a field, resolving component refs

func (*ComponentSchemaService) List

List lists component schemas with pagination

func (*ComponentSchemaService) ResolveComponentSchema

func (s *ComponentSchemaService) ResolveComponentSchema(ctx context.Context, componentName string) ([]core.NestedFieldDefDTO, error)

ResolveComponentSchema resolves a component reference and returns the nested fields

func (*ComponentSchemaService) Update

Update updates a component schema

func (*ComponentSchemaService) ValidateComponentRef

func (s *ComponentSchemaService) ValidateComponentRef(ctx context.Context, componentSlug string, visited []string) error

ValidateComponentRef validates that a component reference is valid and not circular

type ComponentSchemaServiceConfig

type ComponentSchemaServiceConfig struct {
	MaxComponentSchemas int
	Logger              forge.Logger
}

ComponentSchemaServiceConfig holds configuration for the service

type ContentEntryService

type ContentEntryService struct {
	// contains filtered or unexported fields
}

ContentEntryService handles content entry business logic

func NewContentEntryService

NewContentEntryService creates a new content entry service

func (*ContentEntryService) Archive

Archive archives a content entry

func (*ContentEntryService) BulkDelete

func (s *ContentEntryService) BulkDelete(ctx context.Context, ids []xid.ID) error

BulkDelete deletes multiple entries

func (*ContentEntryService) BulkPublish

func (s *ContentEntryService) BulkPublish(ctx context.Context, ids []xid.ID) error

BulkPublish publishes multiple entries

func (*ContentEntryService) BulkUnpublish

func (s *ContentEntryService) BulkUnpublish(ctx context.Context, ids []xid.ID) error

BulkUnpublish unpublishes multiple entries

func (*ContentEntryService) Create

func (s *ContentEntryService) Create(ctx context.Context, contentTypeID xid.ID, req *core.CreateEntryRequest) (*core.ContentEntryDTO, error)

Create creates a new content entry

func (*ContentEntryService) Delete

func (s *ContentEntryService) Delete(ctx context.Context, id xid.ID) error

Delete deletes a content entry

func (*ContentEntryService) GetByID

GetByID retrieves a content entry by ID

func (*ContentEntryService) GetStats

func (s *ContentEntryService) GetStats(ctx context.Context, contentTypeID xid.ID) (*core.ContentTypeStatsDTO, error)

GetStats returns statistics for entries

func (*ContentEntryService) List

func (s *ContentEntryService) List(ctx context.Context, contentTypeID xid.ID, query *core.ListEntriesQuery) (*core.ListEntriesResponse, error)

List lists content entries with filtering and pagination

func (*ContentEntryService) ProcessScheduledEntries

func (s *ContentEntryService) ProcessScheduledEntries(ctx context.Context) (int, error)

ProcessScheduledEntries processes entries scheduled for publishing

func (*ContentEntryService) Publish

Publish publishes a content entry

func (*ContentEntryService) Restore

func (s *ContentEntryService) Restore(ctx context.Context, id xid.ID, version int) (*core.ContentEntryDTO, error)

Restore restores an entry to a specific revision version

func (*ContentEntryService) Unpublish

func (s *ContentEntryService) Unpublish(ctx context.Context, id xid.ID) (*core.ContentEntryDTO, error)

Unpublish unpublishes a content entry

func (*ContentEntryService) Update

Update updates a content entry

type ContentEntryServiceConfig

type ContentEntryServiceConfig struct {
	EnableRevisions      bool
	MaxRevisionsPerEntry int
	Logger               forge.Logger
}

ContentEntryServiceConfig holds configuration for the service

type ContentFieldService

type ContentFieldService struct {
	// contains filtered or unexported fields
}

ContentFieldService handles content field business logic

func NewContentFieldService

NewContentFieldService creates a new content field service

func (*ContentFieldService) Create

func (s *ContentFieldService) Create(ctx context.Context, contentTypeID xid.ID, req *core.CreateFieldRequest) (*core.ContentFieldDTO, error)

Create creates a new content field

func (*ContentFieldService) Delete

func (s *ContentFieldService) Delete(ctx context.Context, id xid.ID) error

Delete deletes a content field

func (*ContentFieldService) DeleteByName

func (s *ContentFieldService) DeleteByName(ctx context.Context, contentTypeID xid.ID, name string) error

DeleteBySlug deletes a content field by its name within a content type

func (*ContentFieldService) GetByID

GetByID retrieves a content field by ID

func (*ContentFieldService) GetByName

func (s *ContentFieldService) GetByName(ctx context.Context, contentTypeID xid.ID, name string) (*core.ContentFieldDTO, error)

GetBySlug retrieves a content field by slug

func (*ContentFieldService) GetFieldWithResolvedNested

func (s *ContentFieldService) GetFieldWithResolvedNested(ctx context.Context, id xid.ID) (*core.ContentFieldDTO, error)

GetFieldWithResolvedNested returns a field DTO with resolved nested fields

func (*ContentFieldService) List

func (s *ContentFieldService) List(ctx context.Context, contentTypeID xid.ID) ([]*core.ContentFieldDTO, error)

List lists fields for a content type

func (*ContentFieldService) Reorder

func (s *ContentFieldService) Reorder(ctx context.Context, contentTypeID xid.ID, req *core.ReorderFieldsRequest) error

Reorder reorders fields in a content type

func (*ContentFieldService) ResolveNestedFields

func (s *ContentFieldService) ResolveNestedFields(ctx context.Context, field *core.ContentFieldDTO) ([]core.NestedFieldDefDTO, error)

ResolveNestedFields resolves nested fields for a field, handling component refs

func (*ContentFieldService) SetComponentSchemaRepository

func (s *ContentFieldService) SetComponentSchemaRepository(repo repository.ComponentSchemaRepository)

SetComponentSchemaRepository sets the component schema repository

func (*ContentFieldService) SetComponentSchemaService

func (s *ContentFieldService) SetComponentSchemaService(svc *ComponentSchemaService)

SetComponentSchemaService sets the component schema service for resolving component refs

func (*ContentFieldService) Update

Update updates a content field

func (*ContentFieldService) UpdateByName

func (s *ContentFieldService) UpdateByName(ctx context.Context, contentTypeID xid.ID, name string, req *core.UpdateFieldRequest) (*core.ContentFieldDTO, error)

UpdateBySlug updates a content field by its name within a content type

type ContentFieldServiceConfig

type ContentFieldServiceConfig struct {
	MaxFieldsPerType int
	Logger           forge.Logger
}

ContentFieldServiceConfig holds configuration for the service

type ContentTypeService

type ContentTypeService struct {
	// contains filtered or unexported fields
}

ContentTypeService handles content type business logic

func NewContentTypeService

NewContentTypeService creates a new content type service

func (*ContentTypeService) Create

Create creates a new content type

func (*ContentTypeService) Delete

func (s *ContentTypeService) Delete(ctx context.Context, id xid.ID) error

Delete deletes a content type

func (*ContentTypeService) GetByID

func (s *ContentTypeService) GetByID(ctx context.Context, id xid.ID) (*core.ContentTypeDTO, error)

GetByID retrieves a content type by ID

func (*ContentTypeService) GetByName

func (s *ContentTypeService) GetByName(ctx context.Context, name string) (*core.ContentTypeDTO, error)

GetBySlug retrieves a content type by slug

func (*ContentTypeService) GetStats

func (s *ContentTypeService) GetStats(ctx context.Context) (*core.CMSStatsDTO, error)

GetStats returns statistics for content types

func (*ContentTypeService) HardDelete

func (s *ContentTypeService) HardDelete(ctx context.Context, id xid.ID) error

HardDelete permanently deletes a content type and all its data

func (*ContentTypeService) List

List lists content types with filtering and pagination

func (*ContentTypeService) Update

Update updates a content type

type ContentTypeServiceConfig

type ContentTypeServiceConfig struct {
	MaxContentTypes int
	Logger          forge.Logger
}

ContentTypeServiceConfig holds configuration for the service

type EntryValidator

type EntryValidator struct {
	// contains filtered or unexported fields
}

EntryValidator validates content entry data against content type schema

func NewEntryValidator

func NewEntryValidator(contentType *schema.ContentType) *EntryValidator

NewEntryValidator creates a new entry validator for a content type

func (*EntryValidator) ApplyDefaults

func (v *EntryValidator) ApplyDefaults(data map[string]interface{}) map[string]interface{}

ApplyDefaults applies default values to entry data

func (*EntryValidator) GetFieldsForDisplay

func (v *EntryValidator) GetFieldsForDisplay() []*schema.ContentField

GetFieldsForDisplay returns fields that should be displayed (non-hidden)

func (*EntryValidator) GetRelationFields

func (v *EntryValidator) GetRelationFields() []*schema.ContentField

GetRelationFields returns all relation fields

func (*EntryValidator) GetRequiredFields

func (v *EntryValidator) GetRequiredFields() []*schema.ContentField

GetRequiredFields returns all required fields

func (*EntryValidator) GetSearchableFields

func (v *EntryValidator) GetSearchableFields() []*schema.ContentField

GetSearchableFields returns all fields that can be searched

func (*EntryValidator) SanitizeData

func (v *EntryValidator) SanitizeData(data map[string]interface{}) map[string]interface{}

SanitizeData removes hidden and read-only fields from input data

func (*EntryValidator) ValidateCreate

func (v *EntryValidator) ValidateCreate(data map[string]interface{}) *core.ValidationResult

ValidateCreate validates entry data for creation

func (*EntryValidator) ValidateUniqueConstraints

func (v *EntryValidator) ValidateUniqueConstraints(
	data map[string]interface{},
	existingID *xid.ID,
	checkUnique func(field string, value interface{}, excludeID *xid.ID) (bool, error),
) *core.ValidationResult

ValidateUniqueConstraints validates unique constraints (needs to be called separately with DB access)

func (*EntryValidator) ValidateUpdate

func (v *EntryValidator) ValidateUpdate(data map[string]interface{}, existingEntry *schema.ContentEntry) *core.ValidationResult

ValidateUpdate validates entry data for update

type RelationService

type RelationService struct {
	// contains filtered or unexported fields
}

RelationService handles content relations

func NewRelationService

NewRelationService creates a new relation service

func (*RelationService) AddRelation

func (s *RelationService) AddRelation(ctx context.Context, sourceID xid.ID, fieldSlug string, targetID xid.ID) error

AddRelation adds a single relation to existing relations

func (*RelationService) ClearRelations

func (s *RelationService) ClearRelations(ctx context.Context, sourceID xid.ID, fieldSlug string) error

ClearRelations removes all relations for a field

func (*RelationService) CreateTypeRelation

CreateTypeRelation creates a new type relation definition

func (*RelationService) DeleteAllEntryRelations

func (s *RelationService) DeleteAllEntryRelations(ctx context.Context, entryID xid.ID) error

DeleteAllEntryRelations removes all relations for an entry (when deleting entry)

func (*RelationService) DeleteTypeRelation

func (s *RelationService) DeleteTypeRelation(ctx context.Context, id xid.ID) error

DeleteTypeRelation deletes a type relation definition

func (*RelationService) GetRelatedIDs

func (s *RelationService) GetRelatedIDs(ctx context.Context, sourceID xid.ID, fieldSlug string) ([]xid.ID, error)

GetRelatedIDs returns just the IDs of related entries

func (*RelationService) GetRelations

func (s *RelationService) GetRelations(ctx context.Context, sourceID xid.ID, fieldSlug string) ([]*core.RelatedEntryDTO, error)

GetRelations returns all related entries for a field

func (*RelationService) GetReverseRelations

func (s *RelationService) GetReverseRelations(ctx context.Context, targetID xid.ID, fieldSlug string) ([]*core.RelatedEntryDTO, error)

GetReverseRelations returns all entries that reference this entry

func (*RelationService) GetTypeRelation

func (s *RelationService) GetTypeRelation(ctx context.Context, id xid.ID) (*core.TypeRelationDTO, error)

GetTypeRelation gets a type relation by ID

func (*RelationService) GetTypeRelationByField

func (s *RelationService) GetTypeRelationByField(ctx context.Context, contentTypeID xid.ID, fieldSlug string) (*core.TypeRelationDTO, error)

GetTypeRelationByField gets a type relation by content type and field

func (*RelationService) GetTypeRelationsForType

func (s *RelationService) GetTypeRelationsForType(ctx context.Context, contentTypeID xid.ID) ([]*core.TypeRelationDTO, error)

GetTypeRelationsForType gets all type relations for a content type

func (*RelationService) PopulateRelations

func (s *RelationService) PopulateRelations(ctx context.Context, entries []*schema.ContentEntry, fieldSlugs []string) error

PopulateRelations populates relation fields on entries

func (*RelationService) PopulateRelationsMap

func (s *RelationService) PopulateRelationsMap(ctx context.Context, entryID xid.ID, fieldSlugs []string) (map[string][]*core.ContentEntrySummaryDTO, error)

PopulateRelationsMap returns populated relations as a map of field -> entries

func (*RelationService) RemoveRelation

func (s *RelationService) RemoveRelation(ctx context.Context, sourceID xid.ID, fieldSlug string, targetID xid.ID) error

RemoveRelation removes a single relation

func (*RelationService) ReorderRelations

func (s *RelationService) ReorderRelations(ctx context.Context, sourceID xid.ID, fieldSlug string, orderedTargetIDs []xid.ID) error

ReorderRelations reorders the relations for a field

func (*RelationService) SetRelation

func (s *RelationService) SetRelation(ctx context.Context, sourceID xid.ID, fieldSlug string, targetID xid.ID) error

SetRelation sets a single relation (for one-to-one or many-to-one)

func (*RelationService) SetRelations

func (s *RelationService) SetRelations(ctx context.Context, sourceID xid.ID, fieldSlug string, targetIDs []xid.ID) error

SetRelations sets multiple relations (for one-to-many or many-to-many)

func (*RelationService) UpdateTypeRelation

func (s *RelationService) UpdateTypeRelation(ctx context.Context, id xid.ID, req *core.UpdateTypeRelationRequest) (*core.TypeRelationDTO, error)

UpdateTypeRelation updates a type relation definition

type RelationServiceConfig

type RelationServiceConfig struct {
	// MaxRelationsPerField limits relations per field (0 = unlimited)
	MaxRelationsPerField int
	// AllowCircularRelations allows circular references (default: false)
	AllowCircularRelations bool
	// Logger for relation operations
	Logger forge.Logger
}

RelationServiceConfig holds configuration for the relation service

type RevisionService

type RevisionService struct {
	// contains filtered or unexported fields
}

RevisionService handles revision operations

func NewRevisionService

func NewRevisionService(repo repository.RevisionRepository, logger forge.Logger) *RevisionService

NewRevisionService creates a new revision service

func (*RevisionService) CleanupOld

func (s *RevisionService) CleanupOld(ctx context.Context, entryID xid.ID, maxRevisions int) error

CleanupOld removes old revisions exceeding the max count

func (*RevisionService) Compare

func (s *RevisionService) Compare(ctx context.Context, entryID xid.ID, fromVersion, toVersion int) (*core.RevisionCompareDTO, error)

Compare compares two revisions and returns the differences

func (*RevisionService) Create

func (s *RevisionService) Create(ctx context.Context, entryID xid.ID, data map[string]any, changedBy, reason string) (*core.RevisionDTO, error)

Create creates a new revision

func (*RevisionService) GetByVersion

func (s *RevisionService) GetByVersion(ctx context.Context, entryID xid.ID, version int) (*core.RevisionDTO, error)

GetByVersion returns a specific revision by version

func (*RevisionService) List

List returns revisions for an entry

Jump to

Keyboard shortcuts

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