-
Notifications
You must be signed in to change notification settings - Fork 250
/
journal.go
55 lines (50 loc) · 1.67 KB
/
journal.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package model
import (
"context"
"github.com/go-sonic/sonic/consts"
"github.com/go-sonic/sonic/model/dto"
"github.com/go-sonic/sonic/model/param"
"github.com/go-sonic/sonic/model/property"
"github.com/go-sonic/sonic/service"
"github.com/go-sonic/sonic/template"
)
func NewJournalModel(optionService service.OptionService,
themeService service.ThemeService,
journalService service.JournalService,
) *JournalModel {
return &JournalModel{
OptionService: optionService,
ThemeService: themeService,
JournalService: journalService,
}
}
type JournalModel struct {
JournalService service.JournalService
OptionService service.OptionService
ThemeService service.ThemeService
}
func (p *JournalModel) Journals(ctx context.Context, model template.Model, page int) (string, error) {
pageSize := p.OptionService.GetOrByDefault(ctx, property.JournalPageSize).(int)
journalType := consts.JournalTypePublic
journals, total, err := p.JournalService.ListJournal(ctx, param.JournalQuery{
Page: param.Page{PageNum: page, PageSize: pageSize},
Sort: ¶m.Sort{
Fields: []string{"createTime,desc"},
},
Keyword: nil,
JournalType: &journalType,
})
if err != nil {
return "", err
}
journalDTOs, err := p.JournalService.ConvertToWithCommentDTOList(ctx, journals)
if err != nil {
return "", err
}
journalPage := dto.NewPage(journalDTOs, total, param.Page{PageNum: page, PageSize: pageSize})
model["is_journals"] = true
model["journals"] = journalPage
model["meta_keywords"] = p.OptionService.GetOrByDefault(ctx, property.SeoKeywords)
model["meta_description"] = p.OptionService.GetOrByDefault(ctx, property.SeoDescription)
return p.ThemeService.Render(ctx, "journals")
}