read.go 4.19 KB
Newer Older
haoyanbin's avatar
1  
haoyanbin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
package v1

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model/request"
	"gin-vue-admin/model/response"
	"gin-vue-admin/service"
	"gin-vue-admin/utils"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// @Tags report
// @Summary 用id查询目录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetReportInfoReq true "用id查询report"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /read/GetCatalogList [post]
func GetCatalogList(c *gin.Context) {
	var req request.GetReadCatalog
	_ = c.ShouldBindJSON(&req)
	if err, catalogs := service.GetReadCatalog(req.Id); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		reply := utils.GetBookCatalogs(catalogs, 0)
		response.OkWithData(gin.H{"list": reply}, c)
	}
	return
}

// @Tags report
// @Summary 分页获取文章列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetReportListReq true "分页获取文章列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /read/getReadContentList [post]
func GetReadContentList(c *gin.Context) {
	var req request.GetReadContentReq
	_ = c.ShouldBindJSON(&req)
	var err error

	// err, reportList, total := service.GetReportList(req, userId, order)
	err, reportList, total := service.GetAdminReadContent(req)
	if err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
		return
	}

	response.OkWithDetailed(response.PageResult{
		List:     reportList,
		Total:    total,
		Page:     req.Page,
		PageSize: req.PageSize,
	}, "获取成功", c)
	return
}

// @Tags report
// @Summary 分页获取文章列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetReportListReq true "分页获取文章详情"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /read/GetReadContent [post]
func GetReadContent(c *gin.Context) {
	var req request.GetReadContentReq
	_ = c.ShouldBindJSON(&req)
	if err, content := service.GetReadContent(req.ReadCatalogId); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(content, c)
	}
	return
}

// 创建目录
// @Tags report
// @Summary 创建目录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CreateReadCatalog true "创建目录"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /read/createReadCatalog [post]
func CreateReadCatalog(c *gin.Context) {
	var req request.CreateReadCatalog
	_ = c.ShouldBindJSON(&req)
	service.CreateReadCatalog(req)
	response.OkWithMessage("创建成功", c)
}

// 创建文章
// @Tags report
// @Summary 创建文章
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CreateReadContent true "创建文章"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /read/createReadContent [post]
func CreateReadContent(c *gin.Context) {
	var req request.CreateReadContent
	_ = c.ShouldBindJSON(&req)
	service.CreateReadContent(req)
	response.OkWithMessage("创建成功", c)
}

// 更新目录
func UpdateCatalog(c *gin.Context) {
	var req request.CreateReadCatalog
	_ = c.ShouldBindJSON(&req)
	service.UpdateReadCatalog(req)
	response.OkWithMessage("修改成功", c)
}

// 更新文章
func UpdateReadContent(c *gin.Context) {
	var req request.CreateReadContent
	_ = c.ShouldBindJSON(&req)
	service.UpdateReadContent(req)
	response.OkWithMessage("修改成功", c)
}

// 删除目录
func DeleteReadCatalog(c *gin.Context) {
	var req request.CreateReadCatalog
	_ = c.ShouldBindJSON(&req)
	service.DeleteReadCatalog(req)
	response.OkWithMessage("修改成功", c)
}

// 删除文章
func DeleteReadContent(c *gin.Context) {
	var req request.CreateReadContent
	_ = c.ShouldBindJSON(&req)
	service.DeleteReadContent(req)
	response.OkWithMessage("修改成功", c)
}