about summary refs log tree commit diff
path: root/app/controllers/api/v1/announcements_controller.rb
blob: ee79fc19f1edacd1222a7a900f4451f85cfdb22a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

class Api::V1::AnnouncementsController < Api::BaseController
  before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: :dismiss
  before_action :require_user!
  before_action :set_announcements, only: :index
  before_action :set_announcement, except: :index

  def index
    render json: @announcements, each_serializer: REST::AnnouncementSerializer
  end

  def dismiss
    AnnouncementMute.find_or_create_by!(account: current_account, announcement: @announcement)
    render_empty
  end

  private

  def set_announcements
    @announcements = begin
      Announcement.published.chronological
    end
  end

  def set_announcement
    @announcement = Announcement.published.find(params[:id])
  end
end