pins_controller.rb 892 B

123456789101112131415161718192021222324252627282930
  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.find_or_create_by!(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], current_user.account_id)
  22. end
  23. end