From 4d66c2d9603581648992bee47ec1e142a2b43297 Mon Sep 17 00:00:00 2001 From: 554325746@qq.com <554325746@qq.com> Date: 星期五, 21 二月 2020 17:34:51 +0800 Subject: [PATCH] add fileStack --- controllers/fileStack.go | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 161 insertions(+), 0 deletions(-) diff --git a/controllers/fileStack.go b/controllers/fileStack.go new file mode 100644 index 0000000..77011e4 --- /dev/null +++ b/controllers/fileStack.go @@ -0,0 +1,161 @@ +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 鏂板鎴栬�呮洿鏂帮紝鏇存柊鏃秈d涓嶈兘涓虹┖ +// @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 "鏁版嵁鏍坕d" +// @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 "鍒犻櫎鏁版嵁鏍坕d" +// @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, "鏇存柊澶辫触") + } +} -- Gitblit v1.8.0