Commit 1bd718a5f8a5268ca580dded82a6c5fc5b8480dd

Authored by Victor Costa
1 parent ad651bba

Ranking pagination

Showing 1 changed file with 4 additions and 1 deletions   Show diff stats
lib/proposals_discussion_plugin/api.rb
... ... @@ -2,9 +2,10 @@ class ProposalsDiscussionPlugin::API < Grape::API
2 2  
3 3 resource :proposals_discussion_plugin do
4 4  
  5 + paginate per_page: 10, max_per_page: 20
5 6 get ':id/ranking' do
6 7 article = find_article(environment.articles, params[:id])
7   - Rails.cache.fetch("#{article.cache_key}/proposals_ranking", expires_in: 10.minutes) do
  8 + ranking = Rails.cache.fetch("#{article.cache_key}/proposals_ranking", expires_in: 10.minutes) do
8 9 max_hits = article.proposals.maximum(:hits)
9 10 min_hits = article.proposals.minimum(:hits)
10 11  
... ... @@ -17,6 +18,8 @@ class ProposalsDiscussionPlugin::API < Grape::API
17 18 proposals = proposals.sort_by { |p| p[:effective_support] }.reverse
18 19 {:proposals => proposals, :updated_at => DateTime.now}
19 20 end
  21 + ranking[:proposals] = paginate ranking[:proposals]
  22 + ranking
20 23 end
21 24  
22 25 end
... ...