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.

30 lines
884 B

  1. # frozen_string_literal: true
  2. class Api::V1::Accounts::PinsController < Api::BaseController
  3. include Authorization
  4. before_action -> { doorkeeper_authorize! :write, :'write:accounts' }
  5. before_action :require_user!
  6. before_action :set_account
  7. def create
  8. AccountPin.create!(account: current_account, target_account: @account)
  9. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships_presenter
  10. end
  11. def destroy
  12. pin = AccountPin.find_by(account: current_account, target_account: @account)
  13. pin&.destroy!
  14. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships_presenter
  15. end
  16. private
  17. def set_account
  18. @account = Account.find(params[:account_id])
  19. end
  20. def relationships_presenter
  21. AccountRelationshipsPresenter.new([@account.id], current_user.account_id)
  22. end
  23. end