Commit f48831f3c3a40bea4267b88b08e61c8ef5e588d4
Committed by
Rodrigo Souto
1 parent
0fff0876
Exists in
master
and in
21 other branches
refactoring community api endpoint
Showing
2 changed files
with
32 additions
and
18 deletions
Show diff stats
lib/api/v1/communities.rb
| @@ -16,11 +16,6 @@ module API | @@ -16,11 +16,6 @@ module API | ||
| 16 | # GET /communities?from=2013-04-04-14:41:43&until=2014-04-04-14:41:43&limit=10 | 16 | # GET /communities?from=2013-04-04-14:41:43&until=2014-04-04-14:41:43&limit=10 |
| 17 | # GET /communities?reference_id=10&limit=10&oldest | 17 | # GET /communities?reference_id=10&limit=10&oldest |
| 18 | get do | 18 | get do |
| 19 | - communities = select_filtered_collection_of(current_person, 'communities', params) | ||
| 20 | - present communities, :with => Entities::Community | ||
| 21 | - end | ||
| 22 | - | ||
| 23 | - get '/all' do | ||
| 24 | communities = select_filtered_collection_of(environment, 'communities', params) | 19 | communities = select_filtered_collection_of(environment, 'communities', params) |
| 25 | communities = communities.visible | 20 | communities = communities.visible |
| 26 | present communities, :with => Entities::Community | 21 | present communities, :with => Entities::Community |
| @@ -33,6 +28,27 @@ module API | @@ -33,6 +28,27 @@ module API | ||
| 33 | 28 | ||
| 34 | end | 29 | end |
| 35 | 30 | ||
| 31 | + resource :people do | ||
| 32 | + segment '/:person_id' do | ||
| 33 | + resource :communities do | ||
| 34 | + get do | ||
| 35 | + person = environment.people.find(params[:person_id]) | ||
| 36 | + communities = select_filtered_collection_of(person, 'communities', params) | ||
| 37 | + communities = communities.visible | ||
| 38 | + present communities, :with => Entities::Community | ||
| 39 | + end | ||
| 40 | + | ||
| 41 | +# get ':id' do | ||
| 42 | +# person = environment.people.find(params[:person_id]) | ||
| 43 | +# article = find_article(person.articles, params[:id]) | ||
| 44 | +# present article, :with => Entities::Article | ||
| 45 | +# end | ||
| 46 | + | ||
| 47 | + end | ||
| 48 | + end | ||
| 49 | + | ||
| 50 | + end | ||
| 51 | + | ||
| 36 | end | 52 | end |
| 37 | end | 53 | end |
| 38 | end | 54 | end |
test/unit/api/communities_test.rb
| @@ -6,21 +6,10 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -6,21 +6,10 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
| 6 | login_api | 6 | login_api |
| 7 | end | 7 | end |
| 8 | 8 | ||
| 9 | - should 'list user communities' do | ||
| 10 | - community1 = fast_create(Community) | ||
| 11 | - fast_create(Community) | ||
| 12 | - community1.add_member(user.person) | ||
| 13 | - | ||
| 14 | - get "/api/v1/communities?#{params.to_query}" | ||
| 15 | - json = JSON.parse(last_response.body) | ||
| 16 | - assert_equivalent [community1.id], json['communities'].map {|c| c['id']} | ||
| 17 | - end | ||
| 18 | - | ||
| 19 | should 'list all communities' do | 9 | should 'list all communities' do |
| 20 | community1 = fast_create(Community) | 10 | community1 = fast_create(Community) |
| 21 | community2 = fast_create(Community) | 11 | community2 = fast_create(Community) |
| 22 | - | ||
| 23 | - get "/api/v1/communities/all?#{params.to_query}" | 12 | + get "/api/v1/communities?#{params.to_query}" |
| 24 | json = JSON.parse(last_response.body) | 13 | json = JSON.parse(last_response.body) |
| 25 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} | 14 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} |
| 26 | end | 15 | end |
| @@ -37,7 +26,7 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -37,7 +26,7 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
| 37 | community1 = fast_create(Community) | 26 | community1 = fast_create(Community) |
| 38 | fast_create(Community, :visible => false) | 27 | fast_create(Community, :visible => false) |
| 39 | 28 | ||
| 40 | - get "/api/v1/communities/all?#{params.to_query}" | 29 | + get "/api/v1/communities?#{params.to_query}" |
| 41 | json = JSON.parse(last_response.body) | 30 | json = JSON.parse(last_response.body) |
| 42 | assert_equal [community1.id], json['communities'].map {|c| c['id']} | 31 | assert_equal [community1.id], json['communities'].map {|c| c['id']} |
| 43 | end | 32 | end |
| @@ -50,4 +39,13 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -50,4 +39,13 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
| 50 | assert json['community'].blank? | 39 | assert json['community'].blank? |
| 51 | end | 40 | end |
| 52 | 41 | ||
| 42 | +# should 'list user communities' do | ||
| 43 | +# community1 = fast_create(Community) | ||
| 44 | +# fast_create(Community) | ||
| 45 | +# community1.add_member(user.person) | ||
| 46 | +# | ||
| 47 | +# get "/api/v1/communities?#{params.to_query}" | ||
| 48 | +# json = JSON.parse(last_response.body) | ||
| 49 | +# assert_equivalent [community1.id], json['communities'].map {|c| c['id']} | ||
| 50 | +# end | ||
| 53 | end | 51 | end |