add new command api

This commit is contained in:
Jay
2018-12-10 16:11:13 +08:00
parent 35379d5c8c
commit e2f4766436
4 changed files with 47 additions and 1 deletions
+31
View File
@@ -157,3 +157,34 @@ func GetCommandList(c *context.Context) {
},
})
}
// AddLineGroupCommand -
func AddLineGroupCommand(c *context.Context) {
// TODO
bodyStruct := struct {
Cmd string `json:"cmd"`
Message string `json:"message"`
Group string `json:"group"`
}{}
err := c.BindData(&bodyStruct)
if err != nil {
c.DataFormat(nil)
return
}
if len(bodyStruct.Cmd) == 0 || len(bodyStruct.Message) == 0 {
c.DataFormat(nil)
return
}
cmd, err := model.AddCommand(bodyStruct.Cmd, bodyStruct.Message, bodyStruct.Group)
if err != nil {
c.ServerError(nil)
return
}
c.Success(map[string]interface{}{
"cmd": utils.ToMap(cmd),
})
}
+1
View File
@@ -72,6 +72,7 @@ func SetRoutes(r *gin.Engine) {
apiGroup.GET("/line/logs", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetLineMessageLog))
apiGroup.GET("/line/groups", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetLineList))
apiGroup.GET("/line/cmds", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetCommandList))
apiGroup.POST("/line/cmd", context.PatchCtx(api.CheckSession), context.PatchCtx(api.AddLineGroupCommand))
apiGroup.GET("/session", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetSessionData))
apiGroup.GET("/twitch/channel/:chid/opay/bar", context.PatchCtx(api.GetDonateBarStatus))
}