Files
RenewCMS/internal/infrastructure/useCases/entrySupport.go
T

30 lines
778 B
Go

package useCases
import (
"RenewCMS/internal/domain/contenttype"
"RenewCMS/internal/domain/entry"
)
type TypedEntry struct {
entry.Entry
ContentTypeKey string
}
func typedEntry(owner contenttype.ContentType, record entry.Entry) TypedEntry {
record.Data = entry.Project(owner.Fields, record.Data)
return TypedEntry{Entry: record, ContentTypeKey: owner.Key}
}
func ensureUnique(entries entry.Repository, owner contenttype.ContentType, data map[string]any, excludeID uint32) error {
for _, candidate := range entry.UniqueValues(owner.Fields, data) {
taken, err := entries.FindByFieldValue(owner.ID, candidate.Key, candidate.Value, excludeID)
if err != nil {
return err
}
if len(taken) > 0 {
return entry.UniqueViolation(candidate.Key)
}
}
return nil
}