Class: Mihari::Alert
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Mihari::Alert
- Defined in:
- lib/mihari/models/alert.rb
Class Method Summary collapse
- .count(artifact_data: nil, description: nil, source: nil, tag_name: nil, title: nil, from_at: nil, to_at: nil) ⇒ Object
- .search(artifact_data: nil, description: nil, source: nil, tag_name: nil, title: nil, from_at: nil, to_at: nil, limit: 10, page: 1) ⇒ Object
Class Method Details
.count(artifact_data: nil, description: nil, source: nil, tag_name: nil, title: nil, from_at: nil, to_at: nil) ⇒ Object
35 36 37 38 |
# File 'lib/mihari/models/alert.rb', line 35 def count(artifact_data: nil, description: nil, source: nil, tag_name: nil, title: nil, from_at: nil, to_at: nil) relation = build_relation(artifact_data: artifact_data, title: title, description: description, source: source, tag_name: tag_name, from_at: from_at, to_at: to_at) relation.distinct("alerts.id").count end |
.search(artifact_data: nil, description: nil, source: nil, tag_name: nil, title: nil, from_at: nil, to_at: nil, limit: 10, page: 1) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mihari/models/alert.rb', line 13 def search(artifact_data: nil, description: nil, source: nil, tag_name: nil, title: nil, from_at: nil, to_at: nil, limit: 10, page: 1) limit = limit.to_i raise ArgumentError, "limit should be bigger than zero" unless limit.positive? page = page.to_i raise ArgumentError, "page should be bigger than zero" unless page.positive? offset = (page - 1) * limit relation = build_relation(artifact_data: artifact_data, title: title, description: description, source: source, tag_name: tag_name, from_at: from_at, to_at: to_at) # relation = relation.group("alerts.id") alerts = relation.limit(limit).offset(offset).order(id: :desc) alerts.map do |alert| json = AlertSerializer.new(alert).as_json json[:artifacts] = json[:artifacts] || [] json[:tags] = json[:tags] || [] json end end |