feat: custom content types backend
This commit is contained in:
1 parent
ed67b7e70d
commit
58d58f5a04
41 files changed
+4086
-2
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package mappers
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/contenttype"
|
||||
"RenewCMS/internal/infrastructure/persistence/models"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func ContentTypeToDomain(m models.ContentType) (contenttype.ContentType, error) {
|
||||
var fields []contenttype.Field
|
||||
if err := json.Unmarshal([]byte(m.Fields), &fields); err != nil {
|
||||
return contenttype.ContentType{}, err
|
||||
}
|
||||
return contenttype.ContentType{
|
||||
ID: m.ID,
|
||||
Key: m.Key,
|
||||
Name: m.Name,
|
||||
Fields: fields,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ContentTypeToModel(c contenttype.ContentType) (models.ContentType, error) {
|
||||
fields, err := json.Marshal(c.Fields)
|
||||
if err != nil {
|
||||
return models.ContentType{}, err
|
||||
}
|
||||
return models.ContentType{
|
||||
ID: c.ID,
|
||||
Key: c.Key,
|
||||
Name: c.Name,
|
||||
Fields: string(fields),
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package mappers
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/entry"
|
||||
"RenewCMS/internal/infrastructure/persistence/models"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func EntryToDomain(m models.Entry) (entry.Entry, error) {
|
||||
data := map[string]any{}
|
||||
if err := json.Unmarshal([]byte(m.Data), &data); err != nil {
|
||||
return entry.Entry{}, err
|
||||
}
|
||||
return entry.Entry{
|
||||
ID: m.ID,
|
||||
ContentTypeID: m.ContentTypeID,
|
||||
Data: data,
|
||||
CreatedBy: m.CreatedBy,
|
||||
UpdatedBy: m.UpdatedBy,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func EntryToModel(e entry.Entry) (models.Entry, error) {
|
||||
data, err := json.Marshal(e.Data)
|
||||
if err != nil {
|
||||
return models.Entry{}, err
|
||||
}
|
||||
return models.Entry{
|
||||
ID: e.ID,
|
||||
ContentTypeID: e.ContentTypeID,
|
||||
Data: string(data),
|
||||
CreatedBy: e.CreatedBy,
|
||||
UpdatedBy: e.UpdatedBy,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
Reference in new issue
Block a user