add edit command api
This commit is contained in:
parent
a7581c74b5
commit
6e4d93d555
@ -161,3 +161,14 @@ func DeleteCommand(cmd, group string) (err error) {
|
|||||||
_, err = x.Exec(query, cmd, group)
|
_, err = x.Exec(query, cmd, group)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateCommand -
|
||||||
|
func UpdateCommand(cmd, group, message string) (err error) {
|
||||||
|
if len(cmd) == 0 || len(message) == 0 {
|
||||||
|
return errors.New("cmd or message is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
query := `update "public"."commands" set "message" = $1, "mtime" = now() where "cmd" = $2 and "group" = $3`
|
||||||
|
_, err = x.Exec(query, message, cmd, group)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -203,10 +203,9 @@ func DeleteLineGroupCommand(c *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !exist {
|
if !exist {
|
||||||
c.NotFound(nil)
|
c.NotFound("command not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO
|
|
||||||
err = model.DeleteCommand(cmd, g)
|
err = model.DeleteCommand(cmd, g)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ServerError(nil)
|
c.ServerError(nil)
|
||||||
@ -215,3 +214,40 @@ func DeleteLineGroupCommand(c *context.Context) {
|
|||||||
|
|
||||||
c.Success(nil)
|
c.Success(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditLineGroupCommand -
|
||||||
|
func EditLineGroupCommand(c *context.Context) {
|
||||||
|
bodyStruct := struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
}{}
|
||||||
|
cmd, ok := c.Params.Get("cmd")
|
||||||
|
if !ok {
|
||||||
|
c.DataFormat(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
g := c.DefaultQuery("group", "")
|
||||||
|
|
||||||
|
err := c.BindData(&bodyStruct)
|
||||||
|
if err != nil {
|
||||||
|
c.DataFormat(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
exist, err := model.CheckCommand(cmd, g)
|
||||||
|
if err != nil {
|
||||||
|
c.ServerError(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !exist {
|
||||||
|
c.NotFound("command not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = model.UpdateCommand(cmd, g, bodyStruct.Message)
|
||||||
|
if err != nil {
|
||||||
|
c.ServerError(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Success(nil)
|
||||||
|
}
|
||||||
|
@ -73,6 +73,8 @@ func SetRoutes(r *gin.Engine) {
|
|||||||
apiGroup.GET("/line/groups", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetLineList))
|
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.GET("/line/cmds", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetCommandList))
|
||||||
apiGroup.POST("/line/cmd", context.PatchCtx(api.CheckSession), context.PatchCtx(api.AddLineGroupCommand))
|
apiGroup.POST("/line/cmd", context.PatchCtx(api.CheckSession), context.PatchCtx(api.AddLineGroupCommand))
|
||||||
|
apiGroup.DELETE("/line/cmd/:cmd", context.PatchCtx(api.CheckSession), context.PatchCtx(api.DeleteLineGroupCommand))
|
||||||
|
apiGroup.PUT("/line/cmd/:cmd", context.PatchCtx(api.CheckSession), context.PatchCtx(api.EditLineGroupCommand))
|
||||||
apiGroup.GET("/session", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetSessionData))
|
apiGroup.GET("/session", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetSessionData))
|
||||||
apiGroup.GET("/twitch/channel/:chid/opay/bar", context.PatchCtx(api.GetDonateBarStatus))
|
apiGroup.GET("/twitch/channel/:chid/opay/bar", context.PatchCtx(api.GetDonateBarStatus))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user