Class: Spree::Api::V2::Platform::SeatNumberLayoutsController

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

Instance Method Summary collapse

Instance Method Details

#collectionObject

override



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/spree/api/v2/platform/seat_number_layouts_controller.rb', line 14

def collection
  guest = SpreeCmCommissioner::Guest.find(params[:guest_id])
  event_id = guest.event.id

  reserved_seats = SpreeCmCommissioner::Guest
                   .where(event_id: event_id)
                   .where.not(seat_number: nil)
                   .pluck(:seat_number)

  seat_layouts = guest.variant.seat_number_layouts

  # Subtract guest seat numbers from seat layouts
  available_seat_layouts = seat_layouts - reserved_seats

  # Generate the final list of seat structs
  available_seat_layouts.map { |seat| seat_struct(seat) }
end

#indexObject

override



7
8
9
10
11
# File 'app/controllers/spree/api/v2/platform/seat_number_layouts_controller.rb', line 7

def index
  render_serialized_payload do
    collection_serializer.new(collection).serializable_hash
  end
end

#model_classObject



32
33
34
# File 'app/controllers/spree/api/v2/platform/seat_number_layouts_controller.rb', line 32

def model_class
  SpreeCmCommissioner::Guest
end

#resource_serializerObject



36
37
38
# File 'app/controllers/spree/api/v2/platform/seat_number_layouts_controller.rb', line 36

def resource_serializer
  ::SpreeCmCommissioner::Api::V2::Platform::SeatNumberLayoutsSerializer
end