The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

33 lines
905 B

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