42 lines
888 B
Go
42 lines
888 B
Go
package controller
|
|
|
|
import (
|
|
"Blog/internal/service"
|
|
"Blog/third_party/database"
|
|
"Common/consts"
|
|
"Common/model/AjaxResult"
|
|
"Common/model/blog"
|
|
"context"
|
|
"log"
|
|
|
|
"github.com/kataras/iris/v12"
|
|
"github.com/kataras/iris/v12/sessions"
|
|
)
|
|
|
|
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 []blog.BlogDiary
|
|
err := database.RedisTemplate.ZRevRange(ctx, consts.REDIS_BLOG_DIARY_LATEST, 0, 5).ScanSlice(&slices)
|
|
if err != nil {
|
|
log.Println(err)
|
|
ctrl.Ctx.JSON(AjaxResult.Error("加载错误"))
|
|
return
|
|
}
|
|
for i, item := range slices {
|
|
ptr := &slices[i]
|
|
content := service.ContentService.GetContentByCache(item.Id)
|
|
ptr.Content = content
|
|
}
|
|
|
|
ctrl.Ctx.JSON(AjaxResult.Ok(slices))
|
|
}
|