moves the admin api inside of the /admin namespace
This commit is contained in:
24
app/controllers/admin/api/stats_controller.rb
Normal file
24
app/controllers/admin/api/stats_controller.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class Admin::Api::StatsController < Admin::Api::BaseController
|
||||
|
||||
def show
|
||||
unless params[:events].present? || params[:visits].present?
|
||||
return render json: {}, status: :bad_request
|
||||
end
|
||||
|
||||
ds = Ahoy::DataSource.new
|
||||
|
||||
if params[:events].present?
|
||||
event_types = params[:events].split ','
|
||||
event_types.each do |event|
|
||||
ds.add event.titleize, Ahoy::Event.where(name: event).group_by_day(:time).count
|
||||
end
|
||||
end
|
||||
|
||||
if params[:visits].present?
|
||||
ds.add "Visits", Visit.group_by_day(:started_at).count
|
||||
end
|
||||
|
||||
render json: ds.build
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user