Class: Spree::Api::V2::Tenant::VotesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/v2/tenant/votes_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#current_vendor, #render_serialized_payload, #require_tenant

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/spree/api/v2/tenant/votes_controller.rb', line 14

def create
  voting_session = current_vendor.voting_sessions.find(params[:voting_session_id])
  contestant = voting_session.voting_contestants.find(params[:contestant_id])

  processor_params = vote_params.merge(
    device_fingerprint: device_params[:fingerprint],
    voter_identifier: device_params[:identifier],
    public_metadata: params[:public_metadata] || {},
    tenant_id: MultiTenant.current_tenant_id,
    vendor_id: current_vendor.id
  )

  result = SpreeCmCommissioner::VoteProcessor.new(
    voting_session: voting_session,
    contestant: contestant,
    user: spree_current_user,
    params: processor_params,
    request: request
  ).call

  if result.success?
    render_serialized_payload(201) { serialize_resource(result.value) }
  else
    render_error_payload(result.error)
  end
end

#indexObject



8
9
10
11
12
# File 'app/controllers/spree/api/v2/tenant/votes_controller.rb', line 8

def index
  render_serialized_payload do
    serialize_collection(collection)
  end
end