Files
sundynix-plant-be/api/v1/plant/wiki.go
T
2026-02-07 18:01:49 +08:00

109 lines
2.9 KiB
Go

package plant
import (
"sundynix-go/global"
"sundynix-go/model/commom/response"
plantReq "sundynix-go/model/plant/request"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type WikiApi struct{}
// CreateWiki 发布百科
// @Tags 百科
// @Summary 添加百科
// @Security BearerAuth
// @accept application/json
// @Produce application/json
// @Param data body plantReq.CreateWiki true "添加百科"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}"
// @Router /wiki/add [post]
func (a *WikiApi) CreateWiki(c *gin.Context) {
var req plantReq.CreateWiki
if err := c.ShouldBind(&req); err != nil {
response.FailWithMsg("请求参数错误", c)
return
}
err := wikiService.CreateWiki(req)
if err != nil {
global.Logger.Error("添加百科失败", zap.Error(err))
response.FailWithMsg("添加百科失败", c)
return
}
response.OkWithMsg("添加百科成功", c)
}
// UpdateWiki 发布百科
// @Tags 百科
// @Summary 修改百科
// @Security BearerAuth
// @accept application/json
// @Produce application/json
// @Param data body plantReq.UpdateWiki true "修改百科"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}"
// @Router /wiki/update [post]
func (a *WikiApi) UpdateWiki(c *gin.Context) {
var req plantReq.UpdateWiki
if err := c.ShouldBind(&req); err != nil {
response.FailWithMsg("请求参数错误", c)
return
}
err := wikiService.UpdateWiki(req)
if err != nil {
global.Logger.Error("修改百科失败", zap.Error(err))
response.FailWithMsg("修改百科失败", c)
return
}
response.OkWithMsg("修改百科成功", c)
}
// WikiPage 百科分页
// @Tags 百科
// @Summary 分页
// @Security BearerAuth
// @accept application/json
// @Produce application/json
// @Param data body plantReq.WikiPage true "百科分页"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}"
// @Router /wiki/page [post]
func (a *WikiApi) WikiPage(c *gin.Context) {
var req plantReq.WikiPage
if err := c.ShouldBind(&req); err != nil {
response.FailWithMsg("请求参数错误", c)
return
}
list, total, err := wikiService.WikiPage(req)
if err != nil {
global.Logger.Error("分页百科失败", zap.Error(err))
response.FailWithMsg("分页百科失败", c)
return
}
response.OkWithData(response.PageResult{
List: list,
Total: total,
Page: req.Current,
PageSize: req.PageSize,
}, c)
}
// WikiDetail 百科详情
// @Tags 百科
// @Summary 百科详情
// @Security BearerAuth
// @Produce application/json
// @Param id query string true "id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /wiki/detail [get]
func (a *WikiApi) WikiDetail(c *gin.Context) {
id := c.Query("id")
topic, err := wikiService.Detail(id)
if err != nil {
response.FailWithMsg("获取失败", c)
return
}
response.OkWithData(topic, c)
}