Welcome to mirror list, hosted at ThFree Co, Russian Federation.

update_alert_status_service.rb « alert_management « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 73ee654874f9886f16a1aeb1463940eecd8925f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module AlertManagement
  class UpdateAlertStatusService
    def initialize(alert, status)
      @alert = alert
      @status = status
    end

    def execute
      return error('Invalid status') unless AlertManagement::Alert.statuses.key?(status.to_s)

      alert.status = status

      if alert.save
        success
      else
        error(alert.errors.full_messages.to_sentence)
      end
    end

    private

    attr_reader :alert, :status

    def success
      ServiceResponse.success(payload: { alert: alert })
    end

    def error(message)
      ServiceResponse.error(payload: { alert: alert }, message: message)
    end
  end
end