Files
grafana/pkg/services/ngalert/api/notifications.go
T
Yuri Tseretyan d1073deefd Alerting: Time intervals API (read only endpoints) (#81672)
* declare new API and models GettableTimeIntervals, PostableTimeIntervals
* add new actions alert.notifications.time-intervals:read and alert.notifications.time-intervals:write.
* update existing alerting roles with the read action. Add to all alerting roles.
* add integration tests
2024-02-01 15:17:13 -05:00

35 lines
1.1 KiB
Go

package api
import (
"net/http"
"github.com/grafana/grafana/pkg/api/response"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
)
type NotificationsApiHandler struct {
muteTimingService MuteTimingService
}
func NewNotificationsApi(muteTimingService MuteTimingService) NotificationsApi {
return &NotificationsApiHandler{
muteTimingService: muteTimingService,
}
}
func (f *NotificationsApiHandler) handleRouteNotificationsGetTimeInterval(ctx *contextmodel.ReqContext, name string) response.Response {
model, err := f.muteTimingService.GetMuteTiming(ctx.Req.Context(), name, ctx.OrgID)
if err != nil {
return errorToResponse(err)
}
return response.JSON(http.StatusOK, model) // TODO convert to timing interval
}
func (f *NotificationsApiHandler) handleRouteNotificationsGetTimeIntervals(ctx *contextmodel.ReqContext) response.Response {
model, err := f.muteTimingService.GetMuteTimings(ctx.Req.Context(), ctx.OrgID)
if err != nil {
return errorToResponse(err)
}
return response.JSON(http.StatusOK, model) // TODO convert to timing interval
}