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