The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 lines
666 B

  1. # frozen_string_literal: true
  2. class Api::V1::Polls::VotesController < Api::BaseController
  3. include Authorization
  4. before_action -> { doorkeeper_authorize! :write, :'write:statuses' }
  5. before_action :require_user!
  6. before_action :set_poll
  7. respond_to :json
  8. def create
  9. VoteService.new.call(current_account, @poll, vote_params[:choices])
  10. render json: @poll, serializer: REST::PollSerializer
  11. end
  12. private
  13. def set_poll
  14. @poll = Poll.attached.find(params[:poll_id])
  15. authorize @poll.status, :show?
  16. rescue Mastodon::NotPermittedError
  17. raise ActiveRecord::RecordNotFound
  18. end
  19. def vote_params
  20. params.permit(choices: [])
  21. end
  22. end