feat(alerting): basic support for creating and updating notifications

This commit is contained in:
bergquist
2016-06-16 14:29:20 +02:00
parent 00fc2e2593
commit 7f767224af
10 changed files with 197 additions and 48 deletions
+17 -4
View File
@@ -169,20 +169,33 @@ func GetAlertNotifications(c *middleware.Context) Response {
return Json(200, query.Result)
}
func CreateAlertNotification(c *middleware.Context, cmd *models.CreateAlertNotificationCommand) Response {
func GetAlertNotificationById(c *middleware.Context) Response {
query := &models.GetAlertNotificationQuery{
OrgID: c.OrgId,
Id: c.ParamsInt64("notificationId"),
}
if err := bus.Dispatch(query); err != nil {
return ApiError(500, "Failed to get alert notifications", err)
}
return Json(200, query.Result[0])
}
func CreateAlertNotification(c *middleware.Context, cmd models.CreateAlertNotificationCommand) Response {
cmd.OrgID = c.OrgId
if err := bus.Dispatch(cmd); err != nil {
if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to create alert notification", err)
}
return Json(200, cmd.Result)
}
func UpdateAlertNotification(c *middleware.Context, cmd *models.UpdateAlertNotificationCommand) Response {
func UpdateAlertNotification(c *middleware.Context, cmd models.UpdateAlertNotificationCommand) Response {
cmd.OrgID = c.OrgId
if err := bus.Dispatch(cmd); err != nil {
if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to update alert notification", err)
}
+3 -1
View File
@@ -252,9 +252,11 @@ func Register(r *macaron.Macaron) {
})
r.Get("/notifications", wrap(GetAlertNotifications))
r.Group("/notification", func() {
r.Post("/", bind(m.CreateAlertNotificationCommand{}), wrap(CreateAlertNotification))
r.Put("/", bind(m.UpdateAlertNotificationCommand{}), wrap(UpdateAlertNotification))
r.Put("/:notificationId", bind(m.UpdateAlertNotificationCommand{}), wrap(UpdateAlertNotification))
r.Get("/:notificationId", wrap(GetAlertNotificationById))
})
r.Get("/changes", wrap(GetAlertChanges))