You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.9 KiB

package setting
import (
"base/app/common"
"base/app/lib/bean"
"base/app/logic/manage/setting"
"github.com/gin-gonic/gin"
)
type Api struct {
}
// All @Title 获取全部接口
func (a *Api) All(c *gin.Context) {
apis := setting.ApiLogic.All()
bean.Response.ResultSuc(c, "操作成功", apis)
}
type argsApiAdd struct {
ParentId uint
ApiName string `binding:"required" label:"api名称"`
ApiPath string `binding:"required" label:"api地址"`
}
// Add @Title 添加api接口
func (a *Api) Add(c *gin.Context) {
args := argsApiAdd{}
if err := c.ShouldBind(&args); err != nil {
bean.Response.ResultFail(c, 10001, common.GetVerErr(err))
return
}
if err := setting.ApiLogic.Add(args.ParentId, args.ApiName, args.ApiPath); err != nil {
bean.Response.ResultFail(c, 10002, err.Error())
return
}
bean.Response.ResultSuc(c, "操作成功", nil)
}
type argsApiEdit struct {
ApiId uint `binding:"required" label:"api"`
argsApiAdd
}
// Edit @Title 编辑api接口
func (a *Api) Edit(c *gin.Context) {
args := argsApiEdit{}
if err := c.ShouldBind(&args); err != nil {
bean.Response.ResultFail(c, 10001, common.GetVerErr(err))
return
}
if err := setting.ApiLogic.Edit(args.ApiId, args.ParentId, args.ApiName, args.ApiPath); err != nil {
bean.Response.ResultFail(c, 10002, err.Error())
return
}
bean.Response.ResultSuc(c, "操作成功", nil)
}
type argsApiDel struct {
ApiId uint `binding:"required" label:"api"`
}
// Del @Title 删除api接口
func (a *Api) Del(c *gin.Context) {
args := argsApiDel{}
if err := c.ShouldBind(&args); err != nil {
bean.Response.ResultFail(c, 10001, common.GetVerErr(err))
return
}
if err := setting.ApiLogic.Del(args.ApiId); err != nil {
bean.Response.ResultFail(c, 10002, err.Error())
return
}
bean.Response.ResultSuc(c, "操作成功", nil)
}
// Select @Title api接口筛选
func (a *Api) Select(c *gin.Context) {
apis := setting.ApiLogic.Select()
bean.Response.ResultSuc(c, "操作成功", apis)
}