Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Forfold committed Jul 6, 2023
1 parent 28aa199 commit 285ab59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 3 additions & 5 deletions alert/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,7 @@ func (s *Store) Feedback(ctx context.Context, alertID int) (f Feedback, err erro
row, err := gadb.New(s.db).AlertFeedback(ctx, int64(alertID))
if errors.Is(err, sql.ErrNoRows) {
return Feedback{
AlertID: alertID,
NoiseReason: "",
AlertID: alertID,
}, nil
}

Expand All @@ -813,15 +812,14 @@ func (s Store) UpdateFeedback(ctx context.Context, feedback *Feedback) error {
return err
}

f, err := (s).Feedback(ctx, feedback.AlertID)
err = validate.Text("Noise Reason", feedback.NoiseReason, 1, 255)
if err != nil {
return err
}
f.NoiseReason = feedback.NoiseReason

err = gadb.New(s.db).SetAlertFeedback(ctx, gadb.SetAlertFeedbackParams{
AlertID: int64(feedback.AlertID),
NoiseReason: sql.NullString{String: f.NoiseReason, Valid: true},
NoiseReason: sql.NullString{String: feedback.NoiseReason, Valid: true},
})
if err != nil {
return err
Expand Down
14 changes: 7 additions & 7 deletions graphql2/graphqlapp/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,17 +365,17 @@ func (a *Alert) NoiseReason(ctx context.Context, raw *alert.Alert) (*string, err
if err != nil {
return nil, err
}
if am.NoiseReason == "" {
return nil, nil
}
return &am.NoiseReason, nil
}

func (m *Mutation) SetAlertNoiseReason(ctx context.Context, input graphql2.SetAlertNoiseReasonInput) (bool, error) {
f := &alert.Feedback{
AlertID: input.AlertID,
}

f.NoiseReason = input.NoiseReason

err := m.AlertStore.UpdateFeedback(ctx, f)
err := m.AlertStore.UpdateFeedback(ctx, &alert.Feedback{
AlertID: input.AlertID,
NoiseReason: input.NoiseReason,
})
if err != nil {
return false, err
}
Expand Down

0 comments on commit 285ab59

Please sign in to comment.