add api: get one alert-subscribe
This commit is contained in:
parent
f58cb923d4
commit
952f6b139d
|
@ -36,6 +36,7 @@ _test
|
|||
/vendor
|
||||
/tmp
|
||||
/pub
|
||||
/n9e
|
||||
|
||||
.alerts
|
||||
.idea
|
||||
|
|
|
@ -40,6 +40,20 @@ func AlertSubscribeGets(groupId int64) (lst []AlertSubscribe, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func AlertSubscribeGet(where string, args ...interface{}) (*AlertSubscribe, error) {
|
||||
var lst []*AlertSubscribe
|
||||
err := DB().Where(where, args...).Find(&lst).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(lst) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return lst[0], nil
|
||||
}
|
||||
|
||||
func (s *AlertSubscribe) Verify() error {
|
||||
if s.Cluster == "" {
|
||||
return errors.New("cluster invalid")
|
||||
|
|
|
@ -185,6 +185,7 @@ func configRoute(r *gin.Engine, version string) {
|
|||
pages.DELETE("/busi-group/:id/alert-mutes", jwtAuth(), user(), bgrw(), alertMuteDel)
|
||||
|
||||
pages.GET("/busi-group/:id/alert-subscribes", jwtAuth(), user(), bgro(), alertSubscribeGets)
|
||||
pages.GET("/alert-subscribe/:sid", jwtAuth(), user(), bgro(), alertSubscribeGet)
|
||||
pages.POST("/busi-group/:id/alert-subscribes", jwtAuth(), user(), bgrw(), alertSubscribeAdd)
|
||||
pages.PUT("/busi-group/:id/alert-subscribes", jwtAuth(), user(), bgrw(), alertSubscribePut)
|
||||
pages.DELETE("/busi-group/:id/alert-subscribes", jwtAuth(), user(), bgrw(), alertSubscribeDel)
|
||||
|
|
|
@ -28,6 +28,26 @@ func alertSubscribeGets(c *gin.Context) {
|
|||
ginx.NewRender(c).Data(lst, err)
|
||||
}
|
||||
|
||||
func alertSubscribeGet(c *gin.Context) {
|
||||
subid := ginx.UrlParamInt64(c, "sid")
|
||||
|
||||
sub, err := models.AlertSubscribeGet("id=?", subid)
|
||||
ginx.Dangerous(err)
|
||||
|
||||
if sub == nil {
|
||||
ginx.NewRender(c, 404).Message("No such alert subscribe")
|
||||
return
|
||||
}
|
||||
|
||||
ugcache := make(map[int64]*models.UserGroup)
|
||||
sub.FillUserGroups(ugcache)
|
||||
|
||||
rulecache := make(map[int64]string)
|
||||
sub.FillRuleName(rulecache)
|
||||
|
||||
ginx.NewRender(c).Data(sub, nil)
|
||||
}
|
||||
|
||||
func alertSubscribeAdd(c *gin.Context) {
|
||||
var f models.AlertSubscribe
|
||||
ginx.BindJSON(c, &f)
|
||||
|
|
Loading…
Reference in New Issue