Class: Api::Partner::UpdatedInventoryFilter

Inherits:
Object
  • Object
show all
Defined in:
app/filters/api/partner/updated_inventory_filter.rb

Overview

Responsible for filtering updated inventories data for partner API This class provides various filtering capabilities for inventory collections based on dates, times, and reasons.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collections = nil) ⇒ UpdatedInventoryFilter

Initialize a new filter instance

Parameters:

  • collections (ActiveRecord::Relation, nil) (defaults to: nil)

    Optional initial collection to filter



15
16
17
18
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 15

def initialize(collections = nil)
  self.collections = collections unless collections.nil?
  @config = {}
end

Instance Attribute Details

#collectionsObject

Returns the value of attribute collections.



11
12
13
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 11

def collections
  @collections
end

#error_messageObject

Returns the value of attribute error_message.



11
12
13
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 11

def error_message
  @error_message
end

Instance Method Details

#build_collectionsActiveRecord::Relation

Build the filtered collections by applying all active filters

Returns:

  • (ActiveRecord::Relation)

    The filtered collection



31
32
33
34
35
36
37
38
39
40
41
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 31

def build_collections
  if filter_params
    _filter_by_start_date
    _filter_by_end_date
    _filter_by_start_time
    _filter_by_end_time
    _filter_by_date_range
    _filter_by_reason
  end
  collections
end

#filter(filter_par) ⇒ Hash?

Set the filter parameters

Parameters:

  • filter_par (Hash)

    The filter parameters to apply

Returns:

  • (Hash, nil)

    Returns the filter parameters if present



23
24
25
26
27
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 23

def filter(filter_par)
  return if filter_par.blank?

  config[:filter] = filter_par
end

#to_collectionsActiveRecord::Relation

Returns the final filtered and ordered collection

Returns:

  • (ActiveRecord::Relation)

    The filtered collection ordered by created_at desc



45
46
47
# File 'app/filters/api/partner/updated_inventory_filter.rb', line 45

def to_collections
  build_collections.order(created_at: :desc)
end