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.

38 lines
852 B

  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.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