Sha256: db6249693b6ba35b1903652fb47bd7cd3652e6521af9c90e301a3dbf1bff6f03

Contents?: true

Size: 1.79 KB

Versions: 8

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module Mihari
  module Controllers
    class AlertsController < BaseController
      get "/api/alerts" do
        param :page, Integer
        param :artifact, String
        param :description, String
        param :source, String
        param :tag, String

        param :from_at, DateTime
        param :fromAt, DateTime
        param :to_at, DateTime
        param :toAt, DateTime

        page = params["page"] || 1
        page = page.to_i
        limit = 10

        artifact_data = params["artifact"]
        description = params["description"]
        source = params["source"]
        tag_name = params["tag"]
        title = params["title"]

        from_at = params["from_at"] || params["fromAt"]
        to_at = params["to_at"] || params["toAt"]

        alerts = Mihari::Alert.search(
          artifact_data: artifact_data,
          description: description,
          from_at: from_at,
          limit: limit,
          page: page,
          source: source,
          tag_name: tag_name,
          title: title,
          to_at: to_at
        )
        total = Mihari::Alert.count(
          artifact_data: artifact_data,
          description: description,
          from_at: from_at,
          source: source,
          tag_name: tag_name,
          title: title,
          to_at: to_at
        )

        json({ alerts: alerts, total: total, current_page: page, page_size: limit })
      end

      delete "/api/alerts/:id" do
        param :id, Integer, required: true

        id = params["id"].to_i

        begin
          alert = Mihari::Alert.find(id)
          alert.destroy

          status 204
          body ""
        rescue ActiveRecord::RecordNotFound
          status 404

          json({ message: "ID:#{id} is not found" })
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mihari-3.8.1 lib/mihari/web/controllers/alerts_controller.rb
mihari-3.8.0 lib/mihari/web/controllers/alerts_controller.rb
mihari-3.7.2 lib/mihari/web/controllers/alerts_controller.rb
mihari-3.7.1 lib/mihari/web/controllers/alerts_controller.rb
mihari-3.7.0 lib/mihari/web/controllers/alerts_controller.rb
mihari-3.6.1 lib/mihari/web/controllers/alerts_controller.rb
mihari-3.6.0 lib/mihari/web/controllers/alerts_controller.rb
mihari-3.5.0 lib/mihari/web/controllers/alerts_controller.rb