mirror of https://github.com/go-sonic/sonic.git
feat: add some api for wordpress
parent
a314f691a8
commit
013b939ac7
@ -0,0 +1,53 @@
|
||||
package wp
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-sonic/sonic/model/dto/wp"
|
||||
"github.com/go-sonic/sonic/model/entity"
|
||||
"github.com/go-sonic/sonic/model/param"
|
||||
"github.com/go-sonic/sonic/service"
|
||||
)
|
||||
|
||||
type TagHandler struct {
|
||||
TagService service.TagService
|
||||
}
|
||||
|
||||
func NewTagHandler(tagService service.TagService) *TagHandler {
|
||||
return &TagHandler{
|
||||
TagService: tagService,
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *TagHandler) List(ctx *gin.Context) (interface{}, error) {
|
||||
var err error
|
||||
var listParam param.TagListParam
|
||||
if err = ctx.ShouldBindJSON(&listParam); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
entities, err := handler.TagService.ListByOption(ctx, &listParam)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tagDTOList := make([]*wp.TagDTO, 0, len(entities))
|
||||
for _, tagEntity := range entities {
|
||||
tagDTOList = append(tagDTOList, convertToWpTag(tagEntity))
|
||||
}
|
||||
|
||||
return tagDTOList, nil
|
||||
}
|
||||
|
||||
func convertToWpTag(tagEntity *entity.Tag) *wp.TagDTO {
|
||||
tagDTO := &wp.TagDTO{
|
||||
ID: tagEntity.ID,
|
||||
Count: 0,
|
||||
Description: "",
|
||||
Link: "",
|
||||
Name: tagEntity.Name,
|
||||
Slug: tagEntity.Slug,
|
||||
Taxonomy: "",
|
||||
Meta: nil,
|
||||
}
|
||||
return tagDTO
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package wp
|
||||
|
||||
type TagDTO struct {
|
||||
ID int32 `json:"id"`
|
||||
Count int32 `json:"count"`
|
||||
Description string `json:"description"`
|
||||
Link string `json:"link"`
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
Taxonomy string `json:"taxonomy"`
|
||||
Meta map[string]interface{} `json:"meta"`
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package param
|
||||
|
||||
type TagListParam struct {
|
||||
Search string `json:"search"`
|
||||
}
|
Loading…
Reference in New Issue