Commit 532cef679340dc0934e2a30fc82af5a34a3cc293

Authored by Tallys Martins
1 parent 0eba5453

API improvements

- Fixed bug on GET enterprise API showing communities and vice-versa.
- Improved POST comment API to recieve multiple params, such as Title.

Signed-off-by: André Bernardes <andrebsguedes@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
lib/noosfero/api/v1/comments.rb
@@ -38,7 +38,8 @@ module Noosfero @@ -38,7 +38,8 @@ module Noosfero
38 # POST api/v1/articles/12/comments?private_toke=234298743290432&body=new comment 38 # POST api/v1/articles/12/comments?private_toke=234298743290432&body=new comment
39 post ":id/comments" do 39 post ":id/comments" do
40 article = find_article(environment.articles, params[:id]) 40 article = find_article(environment.articles, params[:id])
41 - present article.comments.create(:author => current_person, :body => params[:body]), :with => Entities::Comment 41 + options = params[:comment].merge(:author => current_person)
  42 + present article.comments.create(options), :with => Entities::Comment
42 end 43 end
43 end 44 end
44 45
lib/noosfero/api/v1/communities.rb
@@ -19,6 +19,7 @@ module Noosfero @@ -19,6 +19,7 @@ module Noosfero
19 get do 19 get do
20 communities = select_filtered_collection_of(environment, 'communities', params) 20 communities = select_filtered_collection_of(environment, 'communities', params)
21 communities = communities.visible_for_person(current_person) 21 communities = communities.visible_for_person(current_person)
  22 + communities = communities.by_location(params) # Must be the last. May return Exception obj.
22 present communities, :with => Entities::Community 23 present communities, :with => Entities::Community
23 end 24 end
24 25
@@ -41,7 +42,10 @@ module Noosfero @@ -41,7 +42,10 @@ module Noosfero
41 end 42 end
42 43
43 get ':id' do 44 get ':id' do
44 - community = environment.communities.visible.find_by_id(params[:id]) 45 + community = environment.communities.find_by_id(params[:id])
  46 + unless community.nil?
  47 + community = nil unless community.display_info_to?(current_person)
  48 + end
45 present community, :with => Entities::Community 49 present community, :with => Entities::Community
46 end 50 end
47 51
lib/noosfero/api/v1/enterprises.rb
@@ -5,7 +5,7 @@ module Noosfero @@ -5,7 +5,7 @@ module Noosfero
5 before { authenticate! } 5 before { authenticate! }
6 6
7 resource :enterprises do 7 resource :enterprises do
8 - 8 +
9 # Collect enterprises from environment 9 # Collect enterprises from environment
10 # 10 #
11 # Parameters: 11 # Parameters:
@@ -26,7 +26,10 @@ module Noosfero @@ -26,7 +26,10 @@ module Noosfero
26 26
27 desc "Return one enterprise by id" 27 desc "Return one enterprise by id"
28 get ':id' do 28 get ':id' do
29 - enterprise = environment.enterprises.visible.find_by_id(params[:id]) 29 + enterprise = environment.enterprises.find_by_id(params[:id])
  30 + unless enterprise.nil?
  31 + enterprise = nil unless enterprise.display_info_to?(current_person)
  32 + end
30 present enterprise, :with => Entities::Enterprise 33 present enterprise, :with => Entities::Enterprise
31 end 34 end
32 35