Class: Api::V5::TicketsFilter

Inherits:
Object
  • Object
show all
Includes:
PaginationConcernFilter
Defined in:
app/filters/api/v5/tickets_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PaginationConcernFilter

#page_number, #per_page

Constructor Details

#initialize(user = nil) ⇒ TicketsFilter

Returns a new instance of TicketsFilter.



10
11
12
13
14
15
16
17
# File 'app/filters/api/v5/tickets_filter.rb', line 10

def initialize(user = nil)
  @user = user
  @config = {}
  @total = 0

  user_tickets = Ticket.joins(:ticket_transaction).where(ticket_transactions: { user_id: user.id }).active
  self.collections = user_tickets || Ticket.where('1 = 0')
end

Instance Attribute Details

#collectionsObject

Returns the value of attribute collections.



7
8
9
# File 'app/filters/api/v5/tickets_filter.rb', line 7

def collections
  @collections
end

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'app/filters/api/v5/tickets_filter.rb', line 8

def config
  @config
end

#totalObject (readonly)

Returns the value of attribute total.



8
9
10
# File 'app/filters/api/v5/tickets_filter.rb', line 8

def total
  @total
end

#userObject

Returns the value of attribute user.



7
8
9
# File 'app/filters/api/v5/tickets_filter.rb', line 7

def user
  @user
end

Instance Method Details

#as_json(context) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'app/filters/api/v5/tickets_filter.rb', line 27

def as_json(context)
  @total = collections.size
  meta = { total: (@total.presence || 0) }
  ActiveModelSerializers::SerializableResource.new(collections,
                                                   { serialization_context: context,
                                                     serializer: ActiveModel::Serializer::CollectionSerializer,
                                                     each_serializer: Api::V5::TicketSerializer,
                                                     meta: meta,
                                                     user_id: user.id,
                                                     adapter: :json_api }).as_json
end

#build_collectionsObject



23
24
25
# File 'app/filters/api/v5/tickets_filter.rb', line 23

def build_collections
  _build_by_section
end

#section_type(section_type) ⇒ Object



19
20
21
# File 'app/filters/api/v5/tickets_filter.rb', line 19

def section_type(section_type)
  @config[:section_type] = section_type
end