137 lines
3.6 KiB
Go
137 lines
3.6 KiB
Go
package plant
|
|
|
|
import (
|
|
"sundynix-go/global"
|
|
"sundynix-go/model/commom/response"
|
|
plantReq "sundynix-go/model/plant/request"
|
|
"sundynix-go/utils/auth"
|
|
|
|
"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
|
|
err := c.ShouldBind(&req)
|
|
if 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
|
|
err := c.ShouldBind(&req)
|
|
if 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
|
|
err := c.ShouldBind(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("请求参数错误", c)
|
|
return
|
|
}
|
|
userId := auth.GetUserId(c)
|
|
list, total, err := wikiService.WikiPage(req, userId)
|
|
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")
|
|
userId := auth.GetUserId(c)
|
|
topic, err := wikiService.Detail(id, userId)
|
|
if err != nil {
|
|
response.FailWithMsg("获取失败", c)
|
|
return
|
|
}
|
|
response.OkWithData(topic, c)
|
|
}
|
|
|
|
// StarWiki 收藏百科
|
|
// @Tags 百科
|
|
// @Summary 收藏百科
|
|
// @Security BearerAuth
|
|
// @Produce application/json
|
|
// @Param id query string true "百科id"
|
|
// @Param type query string true "收藏类型 1 收藏 2 取消收藏"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"收藏成功"}"
|
|
// @Router /wiki/star [get]
|
|
func (a *WikiApi) StarWiki(c *gin.Context) {
|
|
postId := c.Query("id")
|
|
class := c.Query("type")
|
|
userId := auth.GetUserId(c)
|
|
err := wikiService.StarWiki(userId, postId, class)
|
|
if err != nil {
|
|
global.Logger.Error("操作失败", zap.Error(err))
|
|
response.FailWithMsg("操作失败", c)
|
|
return
|
|
}
|
|
response.OkWithMsg("操作成功", c)
|
|
}
|