1
0

pins_controller.rb 904 B

1234567891011121314151617181920212223242526272829303132
  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. respond_to :json
  8. def create
  9. AccountPin.create!(account: current_account, target_account: @account)
  10. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships_presenter
  11. end
  12. def destroy
  13. pin = AccountPin.find_by(account: current_account, target_account: @account)
  14. pin&.destroy!
  15. render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships_presenter
  16. end
  17. private
  18. def set_account
  19. @account = Account.find(params[:account_id])
  20. end
  21. def relationships_presenter
  22. AccountRelationshipsPresenter.new([@account.id], current_user.account_id)
  23. end
  24. end