reports_controller.rb 867 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. class Api::V1::ReportsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :write, :'write:reports' }, only: [:create]
  4. before_action :require_user!
  5. respond_to :json
  6. def create
  7. @report = ReportService.new.call(
  8. current_account,
  9. reported_account,
  10. status_ids: reported_status_ids,
  11. comment: report_params[:comment],
  12. forward: report_params[:forward]
  13. )
  14. render json: @report, serializer: REST::ReportSerializer
  15. end
  16. private
  17. def reported_status_ids
  18. reported_account.statuses.with_discarded.find(status_ids).pluck(:id)
  19. end
  20. def status_ids
  21. Array(report_params[:status_ids])
  22. end
  23. def reported_account
  24. Account.find(report_params[:account_id])
  25. end
  26. def report_params
  27. params.permit(:account_id, :comment, :forward, status_ids: [])
  28. end
  29. end