announcements_controller.rb 735 B

123456789101112131415161718192021222324252627
  1. # frozen_string_literal: true
  2. class Api::V1::AnnouncementsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: :dismiss
  4. before_action :require_user!
  5. before_action :set_announcements, only: :index
  6. before_action :set_announcement, except: :index
  7. def index
  8. render json: @announcements, each_serializer: REST::AnnouncementSerializer
  9. end
  10. def dismiss
  11. AnnouncementMute.find_or_create_by!(account: current_account, announcement: @announcement)
  12. render_empty
  13. end
  14. private
  15. def set_announcements
  16. @announcements = Announcement.published.chronological
  17. end
  18. def set_announcement
  19. @announcement = Announcement.published.find(params[:id])
  20. end
  21. end