base_controller.rb 681 B

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. class Api::V1::Timelines::BaseController < Api::BaseController
  3. after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
  4. private
  5. def insert_pagination_headers
  6. set_pagination_headers(next_path, prev_path)
  7. end
  8. def pagination_max_id
  9. @statuses.last.id
  10. end
  11. def pagination_since_id
  12. @statuses.first.id
  13. end
  14. def next_path_params
  15. permitted_params.merge(max_id: pagination_max_id)
  16. end
  17. def prev_path_params
  18. permitted_params.merge(min_id: pagination_since_id)
  19. end
  20. def permitted_params
  21. params
  22. .slice(*self.class::PERMITTED_PARAMS)
  23. .permit(*self.class::PERMITTED_PARAMS)
  24. end
  25. end