• haoyanbin's avatar
    1 · 9bf9e037
    haoyanbin authored
    9bf9e037
read.go 4.19 KB
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)
}