Skip to content

Commit

Permalink
Chore: rename Id to ID in alert notification models (#62868)
Browse files Browse the repository at this point in the history
  • Loading branch information
idafurjes committed Feb 3, 2023
1 parent 2e98f50 commit 00d9543
Show file tree
Hide file tree
Showing 18 changed files with 240 additions and 240 deletions.
48 changes: 24 additions & 24 deletions pkg/api/alerting.go
Expand Up @@ -302,7 +302,7 @@ func (hs *HTTPServer) GetAlertNotifications(c *contextmodel.ReqContext) response
}

func (hs *HTTPServer) getAlertNotificationsInternal(c *contextmodel.ReqContext) ([]*alertmodels.AlertNotification, error) {
query := &alertmodels.GetAllAlertNotificationsQuery{OrgId: c.OrgID}
query := &alertmodels.GetAllAlertNotificationsQuery{OrgID: c.OrgID}
return hs.AlertNotificationService.GetAllAlertNotifications(c.Req.Context(), query)
}

Expand All @@ -324,11 +324,11 @@ func (hs *HTTPServer) GetAlertNotificationByID(c *contextmodel.ReqContext) respo
return response.Error(http.StatusBadRequest, "notificationId is invalid", err)
}
query := &alertmodels.GetAlertNotificationsQuery{
OrgId: c.OrgID,
Id: notificationId,
OrgID: c.OrgID,
ID: notificationId,
}

if query.Id == 0 {
if query.ID == 0 {
return response.Error(404, "Alert notification not found", nil)
}

Expand Down Expand Up @@ -358,11 +358,11 @@ func (hs *HTTPServer) GetAlertNotificationByID(c *contextmodel.ReqContext) respo
// 500: internalServerError
func (hs *HTTPServer) GetAlertNotificationByUID(c *contextmodel.ReqContext) response.Response {
query := &alertmodels.GetAlertNotificationsWithUidQuery{
OrgId: c.OrgID,
Uid: web.Params(c.Req)[":uid"],
OrgID: c.OrgID,
UID: web.Params(c.Req)[":uid"],
}

if query.Uid == "" {
if query.UID == "" {
return response.Error(404, "Alert notification not found", nil)
}

Expand Down Expand Up @@ -395,7 +395,7 @@ func (hs *HTTPServer) CreateAlertNotification(c *contextmodel.ReqContext) respon
if err := web.Bind(c.Req, &cmd); err != nil {
return response.Error(http.StatusBadRequest, "bad request data", err)
}
cmd.OrgId = c.OrgID
cmd.OrgID = c.OrgID

res, err := hs.AlertNotificationService.CreateAlertNotificationCommand(c.Req.Context(), &cmd)
if err != nil {
Expand Down Expand Up @@ -429,7 +429,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *contextmodel.ReqContext) respon
if err := web.Bind(c.Req, &cmd); err != nil {
return response.Error(http.StatusBadRequest, "bad request data", err)
}
cmd.OrgId = c.OrgID
cmd.OrgID = c.OrgID

err := hs.fillWithSecureSettingsData(c.Req.Context(), &cmd)
if err != nil {
Expand All @@ -448,8 +448,8 @@ func (hs *HTTPServer) UpdateAlertNotification(c *contextmodel.ReqContext) respon
}

query := alertmodels.GetAlertNotificationsQuery{
OrgId: c.OrgID,
Id: cmd.Id,
OrgID: c.OrgID,
ID: cmd.ID,
}

res, err := hs.AlertNotificationService.GetAlertNotifications(c.Req.Context(), &query)
Expand Down Expand Up @@ -477,8 +477,8 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *contextmodel.ReqContext) r
if err := web.Bind(c.Req, &cmd); err != nil {
return response.Error(http.StatusBadRequest, "bad request data", err)
}
cmd.OrgId = c.OrgID
cmd.Uid = web.Params(c.Req)[":uid"]
cmd.OrgID = c.OrgID
cmd.UID = web.Params(c.Req)[":uid"]

err := hs.fillWithSecureSettingsDataByUID(c.Req.Context(), &cmd)
if err != nil {
Expand All @@ -493,8 +493,8 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *contextmodel.ReqContext) r
}

query := alertmodels.GetAlertNotificationsWithUidQuery{
OrgId: cmd.OrgId,
Uid: cmd.Uid,
OrgID: cmd.OrgID,
UID: cmd.UID,
}

res, err := hs.AlertNotificationService.GetAlertNotificationsWithUid(c.Req.Context(), &query)
Expand All @@ -511,8 +511,8 @@ func (hs *HTTPServer) fillWithSecureSettingsData(ctx context.Context, cmd *alert
}

query := &alertmodels.GetAlertNotificationsQuery{
OrgId: cmd.OrgId,
Id: cmd.Id,
OrgID: cmd.OrgID,
ID: cmd.ID,
}

res, err := hs.AlertNotificationService.GetAlertNotifications(ctx, query)
Expand Down Expand Up @@ -540,8 +540,8 @@ func (hs *HTTPServer) fillWithSecureSettingsDataByUID(ctx context.Context, cmd *
}

query := &alertmodels.GetAlertNotificationsWithUidQuery{
OrgId: cmd.OrgId,
Uid: cmd.Uid,
OrgID: cmd.OrgID,
UID: cmd.UID,
}

res, err := hs.AlertNotificationService.GetAlertNotificationsWithUid(ctx, query)
Expand Down Expand Up @@ -582,8 +582,8 @@ func (hs *HTTPServer) DeleteAlertNotification(c *contextmodel.ReqContext) respon
}

cmd := alertmodels.DeleteAlertNotificationCommand{
OrgId: c.OrgID,
Id: notificationId,
OrgID: c.OrgID,
ID: notificationId,
}

if err := hs.AlertNotificationService.DeleteAlertNotification(c.Req.Context(), &cmd); err != nil {
Expand All @@ -610,8 +610,8 @@ func (hs *HTTPServer) DeleteAlertNotification(c *contextmodel.ReqContext) respon
// 500: internalServerError
func (hs *HTTPServer) DeleteAlertNotificationByUID(c *contextmodel.ReqContext) response.Response {
cmd := alertmodels.DeleteAlertNotificationWithUidCommand{
OrgId: c.OrgID,
Uid: web.Params(c.Req)[":uid"],
OrgID: c.OrgID,
UID: web.Params(c.Req)[":uid"],
}

if err := hs.AlertNotificationService.DeleteAlertNotificationWithUid(c.Req.Context(), &cmd); err != nil {
Expand All @@ -623,7 +623,7 @@ func (hs *HTTPServer) DeleteAlertNotificationByUID(c *contextmodel.ReqContext) r

return response.JSON(http.StatusOK, util.DynMap{
"message": "Notification deleted",
"id": cmd.DeletedAlertNotificationId,
"id": cmd.DeletedAlertNotificationID,
})
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/api/dtos/alerting.go
Expand Up @@ -34,8 +34,8 @@ func formatShort(interval time.Duration) string {

func NewAlertNotification(notification *models.AlertNotification) *AlertNotification {
dto := &AlertNotification{
Id: notification.Id,
Uid: notification.Uid,
Id: notification.ID,
Uid: notification.UID,
Name: notification.Name,
Type: notification.Type,
IsDefault: notification.IsDefault,
Expand Down Expand Up @@ -74,8 +74,8 @@ type AlertNotification struct {

func NewAlertNotificationLookup(notification *models.AlertNotification) *AlertNotificationLookup {
return &AlertNotificationLookup{
Id: notification.Id,
Uid: notification.Uid,
Id: notification.ID,
Uid: notification.UID,
Name: notification.Name,
Type: notification.Type,
IsDefault: notification.IsDefault,
Expand Down
4 changes: 2 additions & 2 deletions pkg/services/alerting/extractor_test.go
Expand Up @@ -206,11 +206,11 @@ func TestAlertRuleExtraction(t *testing.T) {
t.Run("Alert notifications are in DB", func(t *testing.T) {
sqlStore := sqlStore{db: sqlstore.InitTestDB(t)}

firstNotification := models.CreateAlertNotificationCommand{Uid: "notifier1", OrgId: 1, Name: "1"}
firstNotification := models.CreateAlertNotificationCommand{UID: "notifier1", OrgID: 1, Name: "1"}
_, err = sqlStore.CreateAlertNotificationCommand(context.Background(), &firstNotification)
require.Nil(t, err)

secondNotification := models.CreateAlertNotificationCommand{Uid: "notifier2", OrgId: 1, Name: "2"}
secondNotification := models.CreateAlertNotificationCommand{UID: "notifier2", OrgID: 1, Name: "2"}
_, err = sqlStore.CreateAlertNotificationCommand(context.Background(), &secondNotification)
require.Nil(t, err)

Expand Down
68 changes: 34 additions & 34 deletions pkg/services/alerting/models/alert_notification.go
Expand Up @@ -26,9 +26,9 @@ var (
)

type AlertNotification struct {
Id int64 `json:"id"`
Uid string `json:"-"`
OrgId int64 `json:"-"`
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
UID string `json:"-" xorm:"uid"`
OrgID int64 `json:"-" xorm:"org_id"`
Name string `json:"name"`
Type string `json:"type"`
SendReminder bool `json:"sendReminder"`
Expand All @@ -42,7 +42,7 @@ type AlertNotification struct {
}

type CreateAlertNotificationCommand struct {
Uid string `json:"uid"`
UID string `json:"uid"`
Name string `json:"name" binding:"Required"`
Type string `json:"type" binding:"Required"`
SendReminder bool `json:"sendReminder"`
Expand All @@ -52,13 +52,13 @@ type CreateAlertNotificationCommand struct {
Settings *simplejson.Json `json:"settings"`
SecureSettings map[string]string `json:"secureSettings"`

OrgId int64 `json:"-"`
OrgID int64 `json:"-"`
EncryptedSecureSettings map[string][]byte `json:"-"`
}

type UpdateAlertNotificationCommand struct {
Id int64 `json:"id" binding:"Required"`
Uid string `json:"uid"`
ID int64 `json:"id" binding:"Required"`
UID string `json:"uid"`
Name string `json:"name" binding:"Required"`
Type string `json:"type" binding:"Required"`
SendReminder bool `json:"sendReminder"`
Expand All @@ -68,13 +68,13 @@ type UpdateAlertNotificationCommand struct {
Settings *simplejson.Json `json:"settings" binding:"Required"`
SecureSettings map[string]string `json:"secureSettings"`

OrgId int64 `json:"-"`
OrgID int64 `json:"-"`
EncryptedSecureSettings map[string][]byte `json:"-"`
}

type UpdateAlertNotificationWithUidCommand struct {
Uid string `json:"-"`
NewUid string `json:"uid"`
UID string `json:"-"`
NewUID string `json:"uid"`
Name string `json:"name" binding:"Required"`
Type string `json:"type" binding:"Required"`
SendReminder bool `json:"sendReminder"`
Expand All @@ -84,71 +84,71 @@ type UpdateAlertNotificationWithUidCommand struct {
Settings *simplejson.Json `json:"settings" binding:"Required"`
SecureSettings map[string]string `json:"secureSettings"`

OrgId int64 `json:"-"`
OrgID int64 `json:"-"`
}

type DeleteAlertNotificationCommand struct {
Id int64
OrgId int64
ID int64
OrgID int64
}
type DeleteAlertNotificationWithUidCommand struct {
Uid string
OrgId int64
UID string
OrgID int64

DeletedAlertNotificationId int64
DeletedAlertNotificationID int64
}

type GetAlertNotificationUidQuery struct {
Id int64
OrgId int64
ID int64
OrgID int64
}

type GetAlertNotificationsQuery struct {
Name string
Id int64
OrgId int64
ID int64
OrgID int64
}

type GetAlertNotificationsWithUidQuery struct {
Uid string
OrgId int64
UID string
OrgID int64
}

type GetAlertNotificationsWithUidToSendQuery struct {
Uids []string
OrgId int64
UIDs []string
OrgID int64
}

type GetAllAlertNotificationsQuery struct {
OrgId int64
OrgID int64
}

type AlertNotificationState struct {
Id int64
OrgId int64
AlertId int64
NotifierId int64
ID int64 `xorm:"pk autoincr 'id'"`
OrgID int64 `xorm:"org_id"`
AlertID int64 `xorm:"alert_id"`
NotifierID int64 `xorm:"notifier_id"`
State AlertNotificationStateType
Version int64
UpdatedAt int64
AlertRuleStateUpdatedVersion int64
}

type SetAlertNotificationStateToPendingCommand struct {
Id int64
ID int64
AlertRuleStateUpdatedVersion int64
Version int64

ResultVersion int64
}

type SetAlertNotificationStateToCompleteCommand struct {
Id int64
ID int64
Version int64
}

type GetOrCreateNotificationStateQuery struct {
OrgId int64
AlertId int64
NotifierId int64
OrgID int64
AlertID int64
NotifierID int64
}
16 changes: 8 additions & 8 deletions pkg/services/alerting/notifier.go
Expand Up @@ -156,7 +156,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
}

cmd := &alertmodels.SetAlertNotificationStateToCompleteCommand{
Id: notifierState.state.Id,
ID: notifierState.state.ID,
Version: notifierState.state.Version,
}

Expand All @@ -166,7 +166,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
func (n *notificationService) sendNotification(evalContext *EvalContext, notifierState *notifierState) error {
if !evalContext.IsTestRun {
setPendingCmd := &alertmodels.SetAlertNotificationStateToPendingCommand{
Id: notifierState.state.Id,
ID: notifierState.state.ID,
Version: notifierState.state.Version,
AlertRuleStateUpdatedVersion: evalContext.Rule.StateChanges,
}
Expand Down Expand Up @@ -257,7 +257,7 @@ func (n *notificationService) renderAndUploadImage(evalCtx *EvalContext, timeout
}

func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids []string, evalContext *EvalContext) (notifierStateSlice, error) {
query := &alertmodels.GetAlertNotificationsWithUidToSendQuery{OrgId: orgID, Uids: notificationUids}
query := &alertmodels.GetAlertNotificationsWithUidToSendQuery{OrgID: orgID, UIDs: notificationUids}

res, err := n.sqlStore.GetAlertNotificationsWithUidToSend(evalContext.Ctx, query)
if err != nil {
Expand All @@ -268,19 +268,19 @@ func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids [
for _, notification := range res {
not, err := InitNotifier(notification, n.decryptFn, n.notificationService)
if err != nil {
n.log.Error("Could not create notifier", "notifier", notification.Uid, "error", err)
n.log.Error("Could not create notifier", "notifier", notification.UID, "error", err)
continue
}

query := &alertmodels.GetOrCreateNotificationStateQuery{
NotifierId: notification.Id,
AlertId: evalContext.Rule.ID,
OrgId: evalContext.Rule.OrgID,
NotifierID: notification.ID,
AlertID: evalContext.Rule.ID,
OrgID: evalContext.Rule.OrgID,
}

state, err := n.sqlStore.GetOrCreateAlertNotificationState(evalContext.Ctx, query)
if err != nil {
n.log.Error("Could not get notification state.", "notifier", notification.Id, "error", err)
n.log.Error("Could not get notification state.", "notifier", notification.ID, "error", err)
continue
}

Expand Down

0 comments on commit 00d9543

Please sign in to comment.