54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package cli_controller
|
|
|
|
import (
|
|
"Blog/internal/client"
|
|
"Blog/internal/consts"
|
|
"Blog/internal/model"
|
|
"Blog/internal/model/result"
|
|
"Blog/internal/service"
|
|
"context"
|
|
|
|
"github.com/kataras/iris/v12"
|
|
"github.com/kataras/iris/v12/sessions"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type DiaryController struct {
|
|
Ctx iris.Context
|
|
Session *sessions.Session
|
|
}
|
|
|
|
func (ctrl *DiaryController) Get() {
|
|
ctrl.Ctx.View("/blog/diary/index.html")
|
|
}
|
|
|
|
func (ctrl *DiaryController) GetLatest() {
|
|
ctx := context.Background()
|
|
var slices []model.BlogDiary
|
|
err := client.RedisClient().ZRevRange(ctx, consts.REDIS_BLOG_DIARY_LATEST, 0, 2).ScanSlice(&slices)
|
|
if err != nil {
|
|
logrus.Info(err)
|
|
ctrl.Ctx.JSON(result.Error("加载错误"))
|
|
return
|
|
}
|
|
ret := []any{}
|
|
|
|
for i, item := range slices {
|
|
ptr := &slices[i]
|
|
textContent := service.TextContentService.GetContent(item.Id)
|
|
// ptr.Content = content
|
|
if textContent != nil {
|
|
var vo = struct {
|
|
Id string `json:"id"`
|
|
Images string `json:"images"`
|
|
PublishTime int64 `json:"publishTime"`
|
|
Content string `json:"content"`
|
|
}{Id: ptr.Id, Images: ptr.Images, PublishTime: ptr.PublishTime, Content: textContent.Content}
|
|
ret = append(ret, vo)
|
|
|
|
}
|
|
}
|
|
|
|
ctrl.Ctx.JSON(result.Ok(ret))
|
|
}
|