feat(alerting): basic support for creating and updating notifications
This commit is contained in:
+17
-4
@@ -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
@@ -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))
|
||||
|
||||
@@ -7,31 +7,30 @@ import (
|
||||
)
|
||||
|
||||
type AlertNotification struct {
|
||||
Id int64
|
||||
OrgId int64
|
||||
Name string
|
||||
Type string
|
||||
Settings *simplejson.Json
|
||||
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
Id int64 `json:"id"`
|
||||
OrgId int64 `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Settings *simplejson.Json `json:"settings"`
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
}
|
||||
|
||||
type CreateAlertNotificationCommand struct {
|
||||
Name string
|
||||
Type string
|
||||
OrgID int64
|
||||
Settings *simplejson.Json
|
||||
Name string `json:"name" binding:"Required"`
|
||||
Type string `json:"type" binding:"Required"`
|
||||
OrgID int64 `json:"-"`
|
||||
Settings *simplejson.Json `json:"settings"`
|
||||
|
||||
Result *AlertNotification
|
||||
}
|
||||
|
||||
type UpdateAlertNotificationCommand struct {
|
||||
Id int64
|
||||
Name string
|
||||
Type string
|
||||
OrgID int64
|
||||
Settings *simplejson.Json
|
||||
Id int64 `json:"id" binding:"Required"`
|
||||
Name string `json:"name" binding:"Required"`
|
||||
Type string `json:"type" binding:"Required"`
|
||||
OrgID int64 `json:"-"`
|
||||
Settings *simplejson.Json `json:"settings" binding:"Required"`
|
||||
|
||||
Result *AlertNotification
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user