annual_reports_controller.rb 942 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class Api::V1::AnnualReportsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read, :'read:accounts' }, only: :index
  4. before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, except: :index
  5. before_action :require_user!
  6. before_action :set_annual_report, except: :index
  7. def index
  8. with_read_replica do
  9. @presenter = AnnualReportsPresenter.new(GeneratedAnnualReport.where(account_id: current_account.id).pending)
  10. @relationships = StatusRelationshipsPresenter.new(@presenter.statuses, current_account.id)
  11. end
  12. render json: @presenter,
  13. serializer: REST::AnnualReportsSerializer,
  14. relationships: @relationships
  15. end
  16. def read
  17. @annual_report.view!
  18. render_empty
  19. end
  20. private
  21. def set_annual_report
  22. @annual_report = GeneratedAnnualReport.find_by!(account_id: current_account.id, year: params[:id])
  23. end
  24. end