feat: Authors feature backend (and upgraded deprecated mods)

This commit is contained in:
Florian Sylvain committed 2026-10-14 17:45:00 +02:00
1 parent a11338094e
commit b34a173d83
103 files changed
+6454 -240

No files matched your search

@@ -0,0 +1,59 @@
package mappers
import (
"RenewCMS/internal/domain/author"
"RenewCMS/internal/infrastructure/persistence/models"
"encoding/json"
)
const emptyLinks = "[]"
func decodeLinks(raw string) []author.SocialLink {
links := []author.SocialLink{}
if raw == "" {
return links
}
if err := json.Unmarshal([]byte(raw), &links); err != nil || links == nil {
return []author.SocialLink{}
}
return links
}
func encodeLinks(links []author.SocialLink) string {
if len(links) == 0 {
return emptyLinks
}
encoded, err := json.Marshal(links)
if err != nil {
return emptyLinks
}
return string(encoded)
}
func AuthorToDomain(m models.Author, articleCount int) author.Author {
return author.Author{
ID: m.ID,
Name: m.Name,
Slug: m.Slug,
Bio: m.Bio,
AvatarID: m.AvatarID,
Website: m.Website,
SocialLinks: decodeLinks(m.SocialLinks),
UserID: m.UserID,
IsLinked: m.UserID != nil,
ArticleCount: articleCount,
}
}
func AuthorToModel(a author.Author) models.Author {
return models.Author{
ID: a.ID,
Name: a.Name,
Slug: a.Slug,
Bio: a.Bio,
AvatarID: a.AvatarID,
Website: a.Website,
SocialLinks: encodeLinks(a.SocialLinks),
UserID: a.UserID,
}
}