Commit 10856688eafc66a47132c16d0857d0dcc9de6606
Committed by
Rodrigo Souto
1 parent
de713c6d
Exists in
api_tasks
and in
4 other branches
api: votes score order for articles
Showing
1 changed file
with
7 additions
and
0 deletions
Show diff stats
lib/noosfero/api/v1/articles.rb
@@ -31,8 +31,15 @@ module Noosfero | @@ -31,8 +31,15 @@ module Noosfero | ||
31 | 31 | ||
32 | get ':id/children' do | 32 | get ':id/children' do |
33 | article = find_article(environment.articles, params[:id]) | 33 | article = find_article(environment.articles, params[:id]) |
34 | + | ||
35 | + votes_order = params.delete(:order) if params[:order]=='votes_score' | ||
34 | articles = select_filtered_collection_of(article, 'children', params) | 36 | articles = select_filtered_collection_of(article, 'children', params) |
35 | articles = articles.display_filter(current_person, nil) | 37 | articles = articles.display_filter(current_person, nil) |
38 | + | ||
39 | + if votes_order | ||
40 | + articles = articles.joins('left join votes on articles.id=votes.voteable_id').group('articles.id').order('sum(votes.id) DESC') | ||
41 | + end | ||
42 | + | ||
36 | present articles, :with => Entities::Article, :fields => params[:fields] | 43 | present articles, :with => Entities::Article, :fields => params[:fields] |
37 | end | 44 | end |
38 | 45 |