package controllers
|
|
import (
|
"basic.com/valib/logger.git"
|
"basic.com/dbapi.git"
|
"webserver/extend/code"
|
"webserver/extend/util"
|
"github.com/gin-gonic/gin"
|
"strconv"
|
)
|
|
type FileStackController struct {
|
|
}
|
|
// @Security ApiKeyAuth
|
// @Summary 获取数据栈列表
|
// @Description 获取数据栈列表
|
// @Produce json
|
// @Tags 数据栈
|
// @Param name query string false "根据数据栈名称查询"
|
// @Param type query int true "0:全部视频,1:视频,2:图片,3:音频,4:其他数据"
|
// @Param page query int true "当前页"
|
// @Param size query int true "每页数量"
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/fileStack/findAllByPage [get]
|
func (fsc FileStackController) FindAllByPage(c *gin.Context) {
|
name := c.Query("name")
|
page,_ := strconv.Atoi(c.Query("page"))
|
size,_ := strconv.Atoi(c.Query("size"))
|
fType,_ := strconv.Atoi(c.Query("type"))
|
logger.Debug("FindAllFile fileName:",name,"page:",page,"size:",size,"fType:",fType)
|
if page < 0 {
|
page = 1
|
}
|
if size <= 0 {
|
size = 20
|
}
|
var api dbapi.FileStackApi
|
b,d := api.FindAllByPage(name, fType, page, size)
|
if b {
|
util.ResponseFormat(c,code.Success, d)
|
} else {
|
util.ResponseFormat(c,code.ComError, "")
|
}
|
}
|
|
type FileStackSave struct {
|
Id string `json:"id"`
|
Name string `json:"name"`
|
Type int `json:"type"`
|
Enable bool `json:"enable"`
|
IsAutoDelFile bool `json:"isAutoDelFile"`
|
Status int `json:"status"`
|
CreateTime string `json:"createTime"`
|
UpdateTime string `json:"updateTime"`
|
Sort int `json:"sort"`
|
}
|
|
// @Security ApiKeyAuth
|
// @Summary 新增或者更新
|
// @Description 新增或者更新,更新时id不能为空
|
// @Accept json
|
// @Produce json
|
// @Tags 数据栈
|
// @Param reqBody body controllers.FileStackSave true "数据栈结构体"
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/fileStack/save [post]
|
func (fsc FileStackController) Save(c *gin.Context) {
|
var reqBody FileStackSave
|
if err := c.BindJSON(&reqBody);err !=nil {
|
util.ResponseFormat(c, code.RequestParamError, "参数有误")
|
return
|
}
|
paramBody := util.Struct2Map(reqBody)
|
var api dbapi.FileStackApi
|
if api.Save(paramBody) {
|
util.ResponseFormat(c,code.Success, "保存成功")
|
} else {
|
util.ResponseFormat(c,code.ComError,"保存失败")
|
}
|
}
|
|
// @Security ApiKeyAuth
|
// @Summary 查看数据栈详情
|
// @Description 查看数据栈详情
|
// @Produce json
|
// @Tags 数据栈
|
// @Param id path string true "数据栈id"
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/fileStack/show/{id} [get]
|
func (fsc FileStackController) Show(c *gin.Context) {
|
id := c.Param("id")
|
if id == "" {
|
util.ResponseFormat(c, code.RequestParamError, "参数有误")
|
return
|
}
|
var api dbapi.FileStackApi
|
b, d := api.Show(id)
|
if b {
|
util.ResponseFormat(c, code.Success, d)
|
} else {
|
util.ResponseFormat(c, code.ComError, "")
|
}
|
}
|
|
// @Security ApiKeyAuth
|
// @Summary 删除
|
// @Description 删除
|
// @Produce json
|
// @Tags 数据栈
|
// @Param id path string true "删除数据栈id"
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/fileStack/delete/{id} [delete]
|
func (fsc FileStackController) Delete(c *gin.Context) {
|
id := c.Param("id")
|
if id == "" {
|
util.ResponseFormat(c, code.RequestParamError, "参数有误")
|
return
|
}
|
var api dbapi.FileStackApi
|
if api.Delete(id) {
|
util.ResponseFormat(c, code.Success, "删除成功")
|
} else {
|
util.ResponseFormat(c, code.ComError, "删除失败")
|
}
|
}
|
|
type EnableVo struct {
|
Id string `json:"id"`
|
Enable bool `json:"enable"`
|
}
|
|
// @Security ApiKeyAuth
|
// @Summary 切换enable
|
// @Description 切换enable
|
// @Accept json
|
// @Produce json
|
// @Tags 数据栈
|
// @Param reqBody body controllers.EnableVo true "切换enable"
|
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
|
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
|
// @Router /data/api-v/fileStack/changeEnable [post]
|
func (fsc FileStackController) ChangeEnable(c *gin.Context) {
|
var reqBody EnableVo
|
c.BindJSON(&reqBody)
|
if reqBody.Id == "" {
|
util.ResponseFormat(c,code.RequestParamError,"参数有误")
|
return
|
}
|
var api dbapi.FileStackApi
|
if api.ChangeEnable(reqBody.Id, reqBody.Enable) {
|
util.ResponseFormat(c, code.UpdateSuccess, "更新成功")
|
} else {
|
util.ResponseFormat(c, code.UpdateFail, "更新失败")
|
}
|
}
|