Class: Spree::Api::V2::Operator::CheckInsController

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

Constant Summary collapse

CACHE_EXPIRES_IN =

Check-in history data requires fresh/recent data for operator dashboards Short cache duration ensures operators see near real-time check-in activity

1.minute

Instance Method Summary collapse

Instance Method Details

#collectionObject



12
13
14
15
16
17
# File 'app/controllers/spree/api/v2/operator/check_ins_controller.rb', line 12

def collection
  @collection ||= SpreeCmCommissioner::CheckIn
                  .where(checkinable_type: 'Spree::Taxon', checkinable_id: params[:taxon_id])
                  .page(params[:page])
                  .per(params[:per_page])
end

#collection_cache_optsObject

override



20
21
22
23
24
25
# File 'app/controllers/spree/api/v2/operator/check_ins_controller.rb', line 20

def collection_cache_opts
  {
    namespace: Spree::Api::Config[:api_v2_collection_cache_namespace],
    expires_in: CACHE_EXPIRES_IN
  }
end

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/spree/api/v2/operator/check_ins_controller.rb', line 27

def create
  spree_authorize! :create, model_class

  result = SpreeCmCommissioner::CheckIns::CreateBulk.call(
    check_ins_attributes: [{ guest_id: params[:guest_id], check_in_session_id: params[:check_in_session_id] }],
    check_in_by: spree_current_user
  )

  if result.success?
    render_serialized_payload(201) { serialize_resource(result.value[:check_ins][0]) }
  else
    render_error_payload(result.error)
  end
end