2019-11-14 00:02:10 +02: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 13:32:54 +02:00
|
|
|
before_action :set_status
|
2019-11-14 00:02:10 +02:00
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
def create
|
2020-02-27 13:32:54 +02:00
|
|
|
current_account.bookmarks.find_or_create_by!(account: current_account, status: @status)
|
2019-11-14 00:02:10 +02:00
|
|
|
render json: @status, serializer: REST::StatusSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-02-27 13:32:54 +02:00
|
|
|
bookmark = current_account.bookmarks.find_by(status: @status)
|
|
|
|
bookmark&.destroy!
|
2019-11-14 00:02:10 +02:00
|
|
|
|
2020-02-27 13:32:54 +02:00
|
|
|
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, bookmarks_map: { @status.id => false })
|
2019-11-14 00:02:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-02-27 13:32:54 +02:00
|
|
|
def set_status
|
|
|
|
@status = Status.find(params[:status_id])
|
|
|
|
authorize @status, :show?
|
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
2019-11-14 00:02:10 +02:00
|
|
|
end
|
|
|
|
end
|