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.

39 lines
1.0 KiB

  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. respond_to :json
  7. def create
  8. @status = bookmarked_status
  9. render json: @status, serializer: REST::StatusSerializer
  10. end
  11. def destroy
  12. @status = requested_status
  13. @bookmarks_map = { @status.id => false }
  14. bookmark = Bookmark.find_by!(account: current_user.account, status: @status)
  15. bookmark.destroy!
  16. render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_user&.account_id, bookmarks_map: @bookmarks_map)
  17. end
  18. private
  19. def bookmarked_status
  20. authorize_with current_user.account, requested_status, :show?
  21. bookmark = Bookmark.find_or_create_by!(account: current_user.account, status: requested_status)
  22. bookmark.status.reload
  23. end
  24. def requested_status
  25. Status.find(params[:status_id])
  26. end
  27. end