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

override



30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 30

def 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



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

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

#default_resource_includesObject

override



51
52
53
54
55
56
57
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 51

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

#include_details?Boolean

default return true

Returns:

  • (Boolean)


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

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

#indexObject

GET /api/v2/storefront/seat_layouts?



14
15
16
17
18
19
20
21
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 14

def index
  render_serialized_payload do
    collection_serializer.new(
      collection,
      { include: resource_includes, params: serializer_params }
    ).serializable_hash
  end
end

#resourceObject

override



43
44
45
46
47
48
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 43

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

#resource_serializerObject

override



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

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

#serializer_paramsObject

override



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

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)



25
26
27
# File 'app/controllers/spree/api/v2/storefront/seat_layouts_controller.rb', line 25

def show
  render_serialized_payload { serialize_resource(resource) }
end