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.

27 lines
621 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. def create
  8. VoteService.new.call(current_account, @poll, vote_params[:choices])
  9. render json: @poll, serializer: REST::PollSerializer
  10. end
  11. private
  12. def set_poll
  13. @poll = Poll.attached.find(params[:poll_id])
  14. authorize @poll.status, :show?
  15. rescue Mastodon::NotPermittedError
  16. not_found
  17. end
  18. def vote_params
  19. params.permit(choices: [])
  20. end
  21. end