notes_controller.rb 889 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class Api::V1::Accounts::NotesController < 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. if params[:comment].blank?
  9. AccountNote.find_by(account: current_account, target_account: @account)&.destroy
  10. else
  11. @note = AccountNote.find_or_initialize_by(account: current_account, target_account: @account)
  12. @note.comment = params[:comment]
  13. @note.save! if @note.changed?
  14. end
  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], current_user.account_id)
  23. end
  24. end