2017-06-10 09:39:26 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::Statuses::FavouritesController < Api::BaseController
|
|
|
|
include Authorization
|
|
|
|
|
2018-07-05 18:31:35 +02:00
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
|
2017-06-10 09:39:26 +02:00
|
|
|
before_action :require_user!
|
2020-02-21 14:23:41 +01:00
|
|
|
before_action :set_status
|
2017-06-10 09:39:26 +02:00
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
def create
|
2020-02-21 14:23:41 +01:00
|
|
|
FavouriteService.new.call(current_account, @status)
|
2017-07-07 04:02:06 +02:00
|
|
|
render json: @status, serializer: REST::StatusSerializer
|
2017-06-10 09:39:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-02-21 14:23:41 +01:00
|
|
|
UnfavouriteWorker.perform_async(current_account.id, @status.id)
|
|
|
|
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, favourites_map: { @status.id => false })
|
2017-06-10 09:39:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-02-21 14:23:41 +01:00
|
|
|
def set_status
|
|
|
|
@status = Status.find(params[:status_id])
|
|
|
|
authorize @status, :show?
|
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
2017-06-10 09:39:26 +02:00
|
|
|
end
|
|
|
|
end
|