Commit 7e575db7f5b6f4a4571af133f881b6bea48d4746
Exists in
staging
and in
3 other branches
Merge branch 'api_articles_grandchildren' into 'staging'
API - New endpoint: Get grandchildren of a article Added new endpoint to get all **grandchildren** of a specific article. The URI of this endpoint is: `:id/children/:child_id/children` See merge request !6
Showing
4 changed files
with
16 additions
and
4 deletions
Show diff stats
lib/noosfero/api/v1/articles.rb
| ... | ... | @@ -203,7 +203,7 @@ module Noosfero |
| 203 | 203 | child.hit |
| 204 | 204 | present_partial child, :with => Entities::Article |
| 205 | 205 | end |
| 206 | - | |
| 206 | + | |
| 207 | 207 | desc 'Suggest a article to another profile' do |
| 208 | 208 | detail 'Suggest a article to another profile (person, community...)' |
| 209 | 209 | params Noosfero::API::Entities::Article.documentation | ... | ... |
lib/noosfero/api/v1/search.rb
| ... | ... | @@ -18,6 +18,7 @@ module Noosfero |
| 18 | 18 | scope = scope.where(:type => params[:type]) if params[:type] && !(params[:type] == 'Article') |
| 19 | 19 | scope = scope.where(:parent_id => params[:parent_id]) if params[:parent_id].present? |
| 20 | 20 | scope = scope.joins(:categories).where(:categories => {:id => params[:category_ids]}) if params[:category_ids].present? |
| 21 | + scope = scope.where('children_count > 0') if params[:has_children].present? | |
| 21 | 22 | query = params[:query] || "" |
| 22 | 23 | order = "more_recent" |
| 23 | 24 | ... | ... |
test/unit/api/articles_test.rb
| ... | ... | @@ -40,11 +40,12 @@ class ArticlesTest < ActiveSupport::TestCase |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | 42 | should 'list article children' do |
| 43 | - article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
| 44 | - child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing") | |
| 45 | - child2 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing") | |
| 43 | + article = create(Article, :profile_id => user.person.id, :name => "Parent") | |
| 44 | + child1 = create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some Child") | |
| 45 | + child2 = create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some Child2") | |
| 46 | 46 | get "/api/v1/articles/#{article.id}/children?#{params.to_query}" |
| 47 | 47 | json = JSON.parse(last_response.body) |
| 48 | + | |
| 48 | 49 | assert_equivalent [child1.id, child2.id], json["articles"].map { |a| a["id"] } |
| 49 | 50 | end |
| 50 | 51 | ... | ... |
test/unit/api/search_test.rb
| ... | ... | @@ -23,6 +23,16 @@ class SearchTest < ActiveSupport::TestCase |
| 23 | 23 | assert_not_empty json['articles'] |
| 24 | 24 | end |
| 25 | 25 | |
| 26 | + should 'list only articles that has children' do | |
| 27 | + article = fast_create(Article, :profile_id => person.id) | |
| 28 | + parent = create(Article, :profile_id => person.id, :name => 'parent article') | |
| 29 | + child = create(Article, :profile_id => person.id, :parent_id => parent.id, :name => 'child article') | |
| 30 | + | |
| 31 | + get "/api/v1/search/article?has_children=true" | |
| 32 | + json = JSON.parse(last_response.body) | |
| 33 | + assert_equal parent.id, json['articles'].first['id'] | |
| 34 | + end | |
| 35 | + | |
| 26 | 36 | should 'invalid search string articles' do |
| 27 | 37 | fast_create(Article, :profile_id => person.id, :name => 'some article') |
| 28 | 38 | get "/api/v1/search/article?query=test" | ... | ... |