Commit b2c5a6a0 by bergquist

fix(alerting): pause dto can only pause one

parent a2257ec3
......@@ -259,11 +259,10 @@ func NotificationTest(c *middleware.Context, dto dtos.NotificationTestCommand) R
//POST /api/alerts/:alertId/pause
func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
alertId := c.ParamsInt64("alertId")
cmd := models.PauseAlertCommand{
OrgId: c.OrgId,
AlertIds: []int64{alertId},
Paused: dto.Paused,
OrgId: c.OrgId,
AlertId: c.ParamsInt64("alertId"),
Paused: dto.Paused,
}
if err := bus.Dispatch(&cmd); err != nil {
......@@ -278,7 +277,7 @@ func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
}
result := map[string]interface{}{
"alertId": alertId,
"alertId": c.ParamsInt64("alertId"),
"state": response,
"message": "alert " + pausedState,
}
......
......@@ -138,10 +138,9 @@ type SaveAlertsCommand struct {
}
type PauseAlertCommand struct {
OrgId int64
AlertIds []int64
ResultCount int64
Paused bool
OrgId int64
AlertId int64
Paused bool
}
type PauseAllAlertCommand struct {
......
......@@ -3,7 +3,6 @@ package sqlstore
import (
"bytes"
"fmt"
"strings"
"time"
"github.com/go-xorm/xorm"
......@@ -252,31 +251,18 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
func PauseAlert(cmd *m.PauseAlertCommand) error {
return inTransaction(func(sess *xorm.Session) error {
if len(cmd.AlertIds) == 0 {
return fmt.Errorf("command contains no alertids")
}
var buffer bytes.Buffer
params := make([]interface{}, 0)
buffer.WriteString(`UPDATE alert SET state = ?`)
sql := `UPDATE alert SET state = ? WHERE id = ?`
if cmd.Paused {
params = append(params, string(m.AlertStatePaused))
} else {
params = append(params, string(m.AlertStatePending))
}
params = append(params, cmd.AlertId)
buffer.WriteString(` WHERE id IN (?` + strings.Repeat(",?", len(cmd.AlertIds)-1) + `)`)
for _, v := range cmd.AlertIds {
params = append(params, v)
}
res, err := sess.Exec(buffer.String(), params...)
if err != nil {
return err
}
cmd.ResultCount, _ = res.RowsAffected()
return nil
_, err := sess.Exec(sql, params...)
return err
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment