Class: Spree::Api::V2::Storefront::SeatLayoutsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject

This method is used by index: GET /api/v2/storefront/seat_layouts?

override



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 23

def collection
  return @collection if defined?(@collection)

  scope = if include_details?
            SpreeCmCommissioner::SeatLayout.active.includes(:top_level_blocks, seat_sections: :blocks)
          else
            SpreeCmCommissioner::SeatLayout.active
          end

  @collection = scope.joins(:blocks)
                     .where(blocks: { variant_id: params[:variant_ids] })
                     .distinct
end

#collection_serializerObject

override



67
68
69
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 67

def collection_serializer
  SpreeCmCommissioner::V2::Storefront::SeatLayoutSerializer
end

#default_resource_includesObject

override



46
47
48
49
50
51
52
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 46

def default_resource_includes
  [
    'top_level_blocks',
    'seat_sections',
    'seat_sections.blocks'
  ]
end

#include_details?Boolean

default return true

Returns:

  • (Boolean)


77
78
79
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 77

def include_details?
  params.fetch(:include_details, 'true') == 'true'
end

#required_schemaObject

override



55
56
57
58
59
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 55

def required_schema
  return nil unless action_name == 'index'

  SpreeCmCommissioner::SeatLayoutSchema
end

#resourceObject

override



38
39
40
41
42
43
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 38

def resource
  SpreeCmCommissioner::SeatLayout.includes(
    :top_level_blocks,
    { seat_sections: :blocks }
  ).find(params[:id])
end

#resource_serializerObject

override



62
63
64
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 62

def resource_serializer
  SpreeCmCommissioner::V2::Storefront::SeatLayoutSerializer
end

#serializer_paramsObject

override



72
73
74
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 72

def serializer_params
  super.merge(include_details: include_details?)
end

#showObject

GET /api/v2/storefront/seat_layouts/:id

  • include_details=true|false (optional, default: true)



13
14
15
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 13

def show
  render_serialized_payload { serialize_resource(resource) }
end