reactions_controller.rb 739 B

1234567891011121314151617181920212223242526272829
  1. # frozen_string_literal: true
  2. class Api::V1::Announcements::ReactionsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
  4. before_action :require_user!
  5. before_action :set_announcement
  6. before_action :set_reaction, except: :update
  7. def update
  8. @announcement.announcement_reactions.create!(account: current_account, name: params[:id])
  9. render_empty
  10. end
  11. def destroy
  12. @reaction.destroy!
  13. render_empty
  14. end
  15. private
  16. def set_reaction
  17. @reaction = @announcement.announcement_reactions.where(account: current_account).find_by!(name: params[:id])
  18. end
  19. def set_announcement
  20. @announcement = Announcement.published.find(params[:announcement_id])
  21. end
  22. end