You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
830 B

  1. # frozen_string_literal: true
  2. class Api::V1::Statuses::FavouritesController < Api::BaseController
  3. include Authorization
  4. before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
  5. before_action :require_user!
  6. before_action :set_status
  7. def create
  8. FavouriteService.new.call(current_account, @status)
  9. render json: @status, serializer: REST::StatusSerializer
  10. end
  11. def destroy
  12. UnfavouriteWorker.perform_async(current_account.id, @status.id)
  13. render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, favourites_map: { @status.id => false })
  14. end
  15. private
  16. def set_status
  17. @status = Status.find(params[:status_id])
  18. authorize @status, :show?
  19. rescue Mastodon::NotPermittedError
  20. not_found
  21. end
  22. end