Commit 48598ab30045398de38b51438224ce23eadffd0a
Committed by
Rodrigo Souto
1 parent
4d0f608f
Exists in
staging
and in
41 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 | 16 | # GET /communities?from=2013-04-04-14:41:43&until=2014-04-04-14:41:43&limit=10 |
| 17 | 17 | # GET /communities?reference_id=10&limit=10&oldest |
| 18 | 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 | 19 | communities = select_filtered_collection_of(environment, 'communities', params) |
| 25 | 20 | communities = communities.visible |
| 26 | 21 | present communities, :with => Entities::Community |
| ... | ... | @@ -33,6 +28,27 @@ module API |
| 33 | 28 | |
| 34 | 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 | 52 | end |
| 37 | 53 | end |
| 38 | 54 | end | ... | ... |
test/unit/api/communities_test.rb
| ... | ... | @@ -6,21 +6,10 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 6 | 6 | login_api |
| 7 | 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 | 9 | should 'list all communities' do |
| 20 | 10 | community1 = fast_create(Community) |
| 21 | 11 | community2 = fast_create(Community) |
| 22 | - | |
| 23 | - get "/api/v1/communities/all?#{params.to_query}" | |
| 12 | + get "/api/v1/communities?#{params.to_query}" | |
| 24 | 13 | json = JSON.parse(last_response.body) |
| 25 | 14 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} |
| 26 | 15 | end |
| ... | ... | @@ -37,7 +26,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 37 | 26 | community1 = fast_create(Community) |
| 38 | 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 | 30 | json = JSON.parse(last_response.body) |
| 42 | 31 | assert_equal [community1.id], json['communities'].map {|c| c['id']} |
| 43 | 32 | end |
| ... | ... | @@ -50,4 +39,13 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 50 | 39 | assert json['community'].blank? |
| 51 | 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 | 51 | end | ... | ... |