go-wxhelper/api/admin/robot/save.go

32 lines
713 B
Go
Raw Normal View History

package robot
import (
"github.com/gin-gonic/gin"
robotParam "wechat-robot/model/param/robot"
"wechat-robot/pkg/response"
robotService "wechat-robot/service/robot"
)
// Save
// @description: 保存机器人
// @param ctx
func Save(ctx *gin.Context) {
var p robotParam.Save
if err := ctx.ShouldBind(&p); err != nil {
response.New(ctx).SetMsg("参数错误").SetError(err).Fail()
return
}
// 参数校验
if p.Id == "" && (p.HookApi == "" || p.Version == 0) {
response.New(ctx).SetMsg("参数错误").Fail()
return
}
if err := robotService.Save(p); err != nil {
response.New(ctx).SetMsg("保存失败").SetError(err).Fail()
return
}
response.New(ctx).SetMsg("保存成功").Success()
}