Class: Api::V5::TicketsFilter
- Inherits:
-
Object
- Object
- Api::V5::TicketsFilter
- Includes:
- PaginationConcernFilter
- Defined in:
- app/filters/api/v5/tickets_filter.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
Returns the value of attribute collections.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #as_json(context) ⇒ Object
- #build_collections ⇒ Object
-
#initialize(user = nil) ⇒ TicketsFilter
constructor
A new instance of TicketsFilter.
- #section_type(section_type) ⇒ Object
Methods included from PaginationConcernFilter
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
#collections ⇒ Object
Returns the value of attribute collections.
7 8 9 |
# File 'app/filters/api/v5/tickets_filter.rb', line 7 def collections @collections end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'app/filters/api/v5/tickets_filter.rb', line 8 def config @config end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
8 9 10 |
# File 'app/filters/api/v5/tickets_filter.rb', line 8 def total @total end |
#user ⇒ Object
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 = { total: (@total.presence || 0) } ActiveModelSerializers::SerializableResource.new(collections, { serialization_context: context, serializer: ActiveModel::Serializer::CollectionSerializer, each_serializer: Api::V5::TicketSerializer, meta: , user_id: user.id, adapter: :json_api }).as_json end |
#build_collections ⇒ Object
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 |