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.

39 lines
920 B

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