From 10856688eafc66a47132c16d0857d0dcc9de6606 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Sun, 19 Apr 2015 17:42:00 -0300 Subject: [PATCH] api: votes score order for articles --- lib/noosfero/api/v1/articles.rb | 7 +++++++ 1 file changed, 7 insertions(+), 0 deletions(-) diff --git a/lib/noosfero/api/v1/articles.rb b/lib/noosfero/api/v1/articles.rb index 958d244..c78de07 100644 --- a/lib/noosfero/api/v1/articles.rb +++ b/lib/noosfero/api/v1/articles.rb @@ -31,8 +31,15 @@ module Noosfero get ':id/children' do article = find_article(environment.articles, params[:id]) + + votes_order = params.delete(:order) if params[:order]=='votes_score' articles = select_filtered_collection_of(article, 'children', params) articles = articles.display_filter(current_person, nil) + + if votes_order + articles = articles.joins('left join votes on articles.id=votes.voteable_id').group('articles.id').order('sum(votes.id) DESC') + end + present articles, :with => Entities::Article, :fields => params[:fields] end -- libgit2 0.21.2