retention_controller.rb 546 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class Api::V1::Admin::RetentionController < Api::BaseController
  3. include Authorization
  4. before_action -> { authorize_if_got_token! :'admin:read' }
  5. before_action :set_cohorts
  6. after_action :verify_authorized
  7. def create
  8. authorize :dashboard, :index?
  9. render json: @cohorts, each_serializer: REST::Admin::CohortSerializer
  10. end
  11. private
  12. def set_cohorts
  13. @cohorts = Admin::Metrics::Retention.new(
  14. params[:start_at],
  15. params[:end_at],
  16. params[:frequency]
  17. ).cohorts
  18. end
  19. end