mirror of https://github.com/go-sonic/sonic.git
feat: add scrap
parent
927be7bd76
commit
6012ea73d6
@ -1,3 +1,3 @@
|
|||||||
[submodule "resources/template/theme/default-theme-anatole"]
|
[submodule "resources/template/theme/default-theme-anatole"]
|
||||||
path = resources/template/theme/default-theme-anatole
|
path = resources/template/theme/default-theme-anatole
|
||||||
url = https://github.com/go-sonic/default-theme-anatole.git
|
url = https://github.com/textworld/default-theme-anatole.git
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package content
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
"github.com/go-sonic/sonic/model/dto"
|
||||||
|
"github.com/go-sonic/sonic/model/param"
|
||||||
|
"github.com/go-sonic/sonic/service"
|
||||||
|
"github.com/go-sonic/sonic/template"
|
||||||
|
"github.com/go-sonic/sonic/util"
|
||||||
|
"github.com/go-sonic/sonic/util/xerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ScrapHandler struct {
|
||||||
|
ScrapService service.ScrapService
|
||||||
|
ThemeService service.ThemeService
|
||||||
|
OptionService service.OptionService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewScrapHandler(scrapService service.ScrapService, themeService service.ThemeService, optionService service.OptionService) *ScrapHandler {
|
||||||
|
return &ScrapHandler{
|
||||||
|
ScrapService: scrapService,
|
||||||
|
ThemeService: themeService,
|
||||||
|
OptionService: optionService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (handler *ScrapHandler) Index(ctx *gin.Context, model template.Model) (string, error) {
|
||||||
|
pageSize := handler.OptionService.GetIndexPageSize(ctx)
|
||||||
|
|
||||||
|
page, err := util.GetQueryInt32(ctx, "page", 1)
|
||||||
|
if err != nil {
|
||||||
|
return "", xerr.WithStatus(nil, int(xerr.StatusBadRequest)).WithMsg("查询不到文章信息")
|
||||||
|
}
|
||||||
|
query := ¶m.ScrapPageQuery{
|
||||||
|
Page: param.Page{
|
||||||
|
PageNum: int(page),
|
||||||
|
PageSize: pageSize,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pageList, total, err := handler.ScrapService.Query(ctx, query)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
model["pages"] = dto.NewPage(pageList, total, param.Page{
|
||||||
|
PageNum: int(page),
|
||||||
|
PageSize: pageSize,
|
||||||
|
})
|
||||||
|
return handler.ThemeService.Render(ctx, "scrap")
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
type ScrapPageDTO struct {
|
||||||
|
ID int32 `json:"id"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Summary string `json:"summary"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
@ -1,11 +1,18 @@
|
|||||||
package param
|
package param
|
||||||
|
|
||||||
type ScrapPage struct {
|
type ScrapPage struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title" form:"title"`
|
||||||
Summary *string `json:"summary"`
|
Summary *string `json:"summary" form:"summary"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url" form:"url"`
|
||||||
OriginURL string `json:"origin_url"`
|
OriginURL string `json:"origin_url" form:"origin_url"`
|
||||||
AddAt *int64 `json:"add_at"`
|
AddAt *int64 `json:"add_at" form:"add_at"`
|
||||||
Md5 string `json:"md_5"`
|
Md5 string `json:"md_5" form:"md_5"`
|
||||||
Content string `json:"content"`
|
Content *string `json:"content" form:"content"`
|
||||||
|
Resource *string `json:"resource" form:"resource"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ScrapPageQuery struct {
|
||||||
|
Page
|
||||||
|
*Sort
|
||||||
|
KeyWord string `json:"key_word"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue