feat(API): media field type
This commit is contained in:
1 parent
ad5faf3d19
commit
a2d596f4ca
63 files changed
+2567
-259
No files matched your search
@@ -3,6 +3,8 @@ package useCases
|
||||
import (
|
||||
"RenewCMS/internal/domain/article"
|
||||
"RenewCMS/internal/domain/author"
|
||||
"RenewCMS/internal/domain/contenttype"
|
||||
"RenewCMS/internal/domain/entry"
|
||||
"RenewCMS/internal/domain/image"
|
||||
"RenewCMS/internal/domain/site"
|
||||
"slices"
|
||||
@@ -13,6 +15,7 @@ const (
|
||||
UsageTypeArticle = "article"
|
||||
UsageTypeAuthor = "author"
|
||||
UsageTypeSite = "site"
|
||||
UsageTypeEntry = "entry"
|
||||
|
||||
UsageFieldBody = "body"
|
||||
UsageFieldCover = "cover"
|
||||
@@ -27,6 +30,16 @@ type MediaUsage struct {
|
||||
Title string
|
||||
Published *bool
|
||||
Fields []string
|
||||
|
||||
ContentTypeKey string
|
||||
ContentTypeName string
|
||||
FirstField *UsageFirstField
|
||||
}
|
||||
|
||||
type UsageFirstField struct {
|
||||
Key string
|
||||
Type contenttype.FieldType
|
||||
Value any
|
||||
}
|
||||
|
||||
type GetMediaUsageUseCase struct {
|
||||
@@ -34,10 +47,11 @@ type GetMediaUsageUseCase struct {
|
||||
articleRepository article.Repository
|
||||
sites site.Repository
|
||||
authors author.Repository
|
||||
entries *entryMediaScanner
|
||||
}
|
||||
|
||||
func NewGetMediaUsageUseCase(imageRepository image.Repository, articleRepository article.Repository, sites site.Repository, authors author.Repository) *GetMediaUsageUseCase {
|
||||
return &GetMediaUsageUseCase{imageRepository: imageRepository, articleRepository: articleRepository, sites: sites, authors: authors}
|
||||
func NewGetMediaUsageUseCase(imageRepository image.Repository, articleRepository article.Repository, sites site.Repository, authors author.Repository, contentTypes contenttype.Repository, entries entry.Repository) *GetMediaUsageUseCase {
|
||||
return &GetMediaUsageUseCase{imageRepository: imageRepository, articleRepository: articleRepository, sites: sites, authors: authors, entries: newEntryMediaScanner(contentTypes, entries)}
|
||||
}
|
||||
|
||||
func (u *GetMediaUsageUseCase) Usage(id uint32) ([]MediaUsage, error) {
|
||||
@@ -57,7 +71,32 @@ func (u *GetMediaUsageUseCase) Usage(id uint32) ([]MediaUsage, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return slices.Concat(usages, authorUsages, siteUsages), nil
|
||||
entryUsages, err := u.entryUsages(img)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return slices.Concat(usages, authorUsages, siteUsages, entryUsages), nil
|
||||
}
|
||||
|
||||
func (u *GetMediaUsageUseCase) entryUsages(img image.Image) ([]MediaUsage, error) {
|
||||
referencing, err := u.entries.referencing(img.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
targets := map[uint32]bool{img.ID: true}
|
||||
usages := make([]MediaUsage, 0, len(referencing))
|
||||
for _, found := range referencing {
|
||||
first := found.owner.Fields[0]
|
||||
usages = append(usages, MediaUsage{
|
||||
Type: UsageTypeEntry,
|
||||
ID: found.record.ID,
|
||||
Fields: found.keysPointingAt(targets),
|
||||
ContentTypeKey: found.owner.Key,
|
||||
ContentTypeName: found.owner.Name,
|
||||
FirstField: &UsageFirstField{Key: first.Key, Type: first.Type, Value: found.record.Data[first.Key]},
|
||||
})
|
||||
}
|
||||
return usages, nil
|
||||
}
|
||||
|
||||
func (u *GetMediaUsageUseCase) articleUsages(img image.Image) ([]MediaUsage, error) {
|
||||
|
||||
Reference in new issue
Block a user