Skip to content
Snippets Groups Projects
Commit 3c91c0fb authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Merge branch 'statistics_controller' into 'master'

Statistics controller

See merge request !370
parents a1cdf55e b40d0d4a
No related branches found
No related tags found
No related merge requests found
class V1::StatisticsController < ApplicationController
def index
statistics = {:count => count_learning_objects, :month_publications => month_publications, :month_downloads => month_downloads}
render json: statistics
end
private
def count_learning_objects
LearningObject.all.count
end
def month_publications
LearningObject.where('extract (month from published_at) = ? and extract (year from published_at) = ?', Time.now.month, Time.now.year).count
end
def month_downloads
end
end
Rails.application.routes.draw do Rails.application.routes.draw do
# require 'sidekiq/web' # require 'sidekiq/web'
# mount Sidekiq::Web, at: '/sidekiq' # mount Sidekiq::Web, at: '/sidekiq'
...@@ -141,6 +142,7 @@ Rails.application.routes.draw do ...@@ -141,6 +142,7 @@ Rails.application.routes.draw do
resources :ratings, except: [:new, :edit] resources :ratings, except: [:new, :edit]
resources :contacts resources :contacts
resources :suggestions resources :suggestions
resources :statistics, only: [:index]
post '/package', to: 'packages#link' post '/package', to: 'packages#link'
get '/subjects', to: 'subjects#index' get '/subjects', to: 'subjects#index'
......
require 'rails_helper'
RSpec.describe StatisticsController, type: :controller do
describe "GET #count_learning_objects" do
it "returns http success" do
get :count_learning_objects
expect(response).to have_http_status(:success)
end
end
describe "GET #month_publications" do
it "returns http success" do
get :month_publications
expect(response).to have_http_status(:success)
end
end
describe "GET #month_downloads" do
it "returns http success" do
get :month_downloads
expect(response).to have_http_status(:success)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment