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.

38 lines
763 B

  1. # frozen_string_literal: true
  2. class Api::V1::Statuses::FavouritesController < Api::BaseController
  3. include Authorization
  4. before_action -> { doorkeeper_authorize! :write }
  5. before_action :require_user!
  6. respond_to :json
  7. def create
  8. @status = favourited_status
  9. render 'api/v1/statuses/show'
  10. end
  11. def destroy
  12. @status = requested_status
  13. @favourites_map = { @status.id => false }
  14. UnfavouriteWorker.perform_async(current_user.account_id, @status.id)
  15. render 'api/v1/statuses/show'
  16. end
  17. private
  18. def favourited_status
  19. service_result.status.reload
  20. end
  21. def service_result
  22. FavouriteService.new.call(current_user.account, requested_status)
  23. end
  24. def requested_status
  25. Status.find(params[:status_id])
  26. end
  27. end