-
Notifications
You must be signed in to change notification settings - Fork 0
/
question.go
38 lines (33 loc) · 992 Bytes
/
question.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package entgo
import (
"github.com/tinygodsdev/orrery/internal/domain"
"github.com/tinygodsdev/orrery/internal/repository/entgo/ent"
)
func entToDomainQuestion(q *ent.Question, locale string) *domain.Question {
content := "no content for this locale: " + locale
headerContent := "no header content for this locale: " + locale
footerContent := "no footer content for this locale: " + locale
if q.Edges.Translations != nil {
if len(q.Edges.Translations) == 1 {
trans := q.Edges.Translations[0]
content = trans.Content
headerContent = trans.HeaderContent
footerContent = trans.FooterContent
}
}
var items []*domain.Item
if q.Edges.Items != nil {
for _, itm := range q.Edges.Items {
items = append(items, entToDomainItem(itm, locale))
}
}
return &domain.Question{
ID: q.ID,
Code: q.Code,
Order: q.Order,
Content: content,
HeaderContent: headerContent,
FooterContent: footerContent,
Items: items,
}
}