2019-11-13 22:02:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::Statuses::BookmarksController < Api::BaseController
|
|
|
|
include Authorization
|
|
|
|
|
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:bookmarks' }
|
|
|
|
before_action :require_user!
|
2020-02-27 11:32:54 +00:00
|
|
|
before_action :set_status
|
2019-11-13 22:02:10 +00:00
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
def create
|
2020-02-27 11:32:54 +00:00
|
|
|
current_account.bookmarks.find_or_create_by!(account: current_account, status: @status)
|
2019-11-13 22:02:10 +00:00
|
|
|
render json: @status, serializer: REST::StatusSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-02-27 11:32:54 +00:00
|
|
|
bookmark = current_account.bookmarks.find_by(status: @status)
|
|
|
|
bookmark&.destroy!
|
2019-11-13 22:02:10 +00:00
|
|
|
|
2020-02-27 11:32:54 +00:00
|
|
|
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, bookmarks_map: { @status.id => false })
|
2019-11-13 22:02:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-02-27 11:32:54 +00:00
|
|
|
def set_status
|
|
|
|
@status = Status.find(params[:status_id])
|
|
|
|
authorize @status, :show?
|
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
2019-11-13 22:02:10 +00:00
|
|
|
end
|
|
|
|
end
|