feat: SEO backend data (1/4)
This commit is contained in:
1 parent
cb1410f0b0
commit
0eb46b0d74
90 files changed
+6094
-350
No files matched your search
@@ -3,27 +3,76 @@ package mappers
|
||||
import (
|
||||
"RenewCMS/internal/domain/article"
|
||||
"RenewCMS/internal/infrastructure/persistence/models"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
const emptyDismissed = "[]"
|
||||
|
||||
func decodeDismissed(raw string) []string {
|
||||
codes := []string{}
|
||||
if raw == "" {
|
||||
return codes
|
||||
}
|
||||
if err := json.Unmarshal([]byte(raw), &codes); err != nil || codes == nil {
|
||||
return []string{}
|
||||
}
|
||||
return codes
|
||||
}
|
||||
|
||||
func encodeDismissed(codes []string) string {
|
||||
if len(codes) == 0 {
|
||||
return emptyDismissed
|
||||
}
|
||||
encoded, err := json.Marshal(codes)
|
||||
if err != nil {
|
||||
return emptyDismissed
|
||||
}
|
||||
return string(encoded)
|
||||
}
|
||||
|
||||
func ArticleToDomain(m models.Article) article.Article {
|
||||
return article.Article{
|
||||
ID: m.ID,
|
||||
Title: m.Title,
|
||||
Body: m.Body,
|
||||
IsOnline: m.IsOnline,
|
||||
SiteID: m.SiteID,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
ID: m.ID,
|
||||
Title: m.Title,
|
||||
Body: m.Body,
|
||||
IsOnline: m.IsOnline,
|
||||
SiteID: m.SiteID,
|
||||
Slug: m.Slug,
|
||||
Excerpt: m.Excerpt,
|
||||
SEOTitle: m.SEOTitle,
|
||||
SEODescription: m.SEODescription,
|
||||
CoverImageID: m.CoverImageID,
|
||||
CoverImageAlt: m.CoverImageAlt,
|
||||
SocialTitle: m.SocialTitle,
|
||||
SocialDescription: m.SocialDescription,
|
||||
SocialImageID: m.SocialImageID,
|
||||
CanonicalURL: m.CanonicalURL,
|
||||
Noindex: m.Noindex,
|
||||
SEODismissed: decodeDismissed(m.SEODismissed),
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func ArticleToModel(a article.Article) models.Article {
|
||||
return models.Article{
|
||||
Title: a.Title,
|
||||
Body: a.Body,
|
||||
IsOnline: a.IsOnline,
|
||||
SiteID: a.SiteID,
|
||||
CreatedAt: a.CreatedAt,
|
||||
UpdatedAt: a.UpdatedAt,
|
||||
Title: a.Title,
|
||||
Body: a.Body,
|
||||
IsOnline: a.IsOnline,
|
||||
SiteID: a.SiteID,
|
||||
Slug: a.Slug,
|
||||
Excerpt: a.Excerpt,
|
||||
SEOTitle: a.SEOTitle,
|
||||
SEODescription: a.SEODescription,
|
||||
CoverImageID: a.CoverImageID,
|
||||
CoverImageAlt: a.CoverImageAlt,
|
||||
SocialTitle: a.SocialTitle,
|
||||
SocialDescription: a.SocialDescription,
|
||||
SocialImageID: a.SocialImageID,
|
||||
CanonicalURL: a.CanonicalURL,
|
||||
Noindex: a.Noindex,
|
||||
SEODismissed: encodeDismissed(a.SEODismissed),
|
||||
CreatedAt: a.CreatedAt,
|
||||
UpdatedAt: a.UpdatedAt,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user