Commit b208ebe6ad83d4776dc8cd42ac93cd4a9dcc9210
Committed by
Thiago Ribeiro
1 parent
4c27fb41
Exists in
master
and in
53 other branches
API improvements for spb plugins
- Added endpoint for Institution in gov_user - Removed community data from SoftwareInfo in software_communities - Software community endpoint restructured Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> (cherry picked from commit 69653c9105b7fbedd01814b17db62e9c930f0c9e)
Showing
7 changed files
with
100 additions
and
13 deletions
Show diff stats
src/noosfero-spb/gov_user/lib/gov_user_plugin.rb
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +require File.dirname(__FILE__) + '/../../../../../lib/noosfero/api/helpers' | |
| 2 | +require_relative 'api_entities' | |
| 3 | + | |
| 4 | +class GovUserPlugin::API < Grape::API | |
| 5 | + | |
| 6 | + include Noosfero::API::APIHelpers | |
| 7 | + | |
| 8 | + resource :gov_user do | |
| 9 | + get 'institutions' do | |
| 10 | + authenticate! | |
| 11 | + institutions = select_filtered_collection_of(environment,'communities',params).joins(:institution) | |
| 12 | + present institutions.map{|o|o.institution}, :with => Entities::Institution | |
| 13 | + end | |
| 14 | + | |
| 15 | + get 'institutions/:id' do | |
| 16 | + authenticate! | |
| 17 | + institution = Institution.find_by_id(params[:id]) | |
| 18 | + present institution, :with => Entities::Institution | |
| 19 | + end | |
| 20 | + | |
| 21 | + end | |
| 22 | +end | |
| 23 | + | ... | ... |
src/noosfero-spb/gov_user/lib/gov_user_plugin/api_entities.rb
0 → 100644
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +module Entities | |
| 2 | + class Institution < Noosfero::API::Entity | |
| 3 | + root 'institutions', 'institution' | |
| 4 | + expose :name, :acronym, :unit_code, :parent_code, :unit_type, | |
| 5 | + :sub_juridical_nature, :normalization_level, | |
| 6 | + :version, :cnpj, :type, :governmental_power, | |
| 7 | + :governmental_sphere, :sisp, :juridical_nature, | |
| 8 | + :corporate_name, :siorg_code, :id | |
| 9 | + expose :community_id do |institution,options| | |
| 10 | + institution.community.id | |
| 11 | + end | |
| 12 | + end | |
| 13 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,51 @@ |
| 1 | +require File.dirname(__FILE__) + '/../../../../test/unit/api/test_helper' | |
| 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | |
| 3 | + | |
| 4 | +class GovUserApiTest < ActiveSupport::TestCase | |
| 5 | + | |
| 6 | + include PluginTestHelper | |
| 7 | + | |
| 8 | + def setup | |
| 9 | + login_api | |
| 10 | + environment = Environment.default | |
| 11 | + environment.enable_plugin(GovUserPlugin) | |
| 12 | + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | |
| 13 | + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
| 14 | + @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
| 15 | + @institution = create_public_institution( | |
| 16 | + "Ministerio Publico da Uniao", | |
| 17 | + "MPU", | |
| 18 | + "BR", | |
| 19 | + "DF", | |
| 20 | + "Gama", | |
| 21 | + @juridical_nature, | |
| 22 | + @gov_power, | |
| 23 | + @gov_sphere, | |
| 24 | + "11.222.333/4444-55") | |
| 25 | + end | |
| 26 | + | |
| 27 | + should 'list all institutions' do | |
| 28 | + @institution1 = create_public_institution( | |
| 29 | + "Instituicao bacana", | |
| 30 | + "IB", | |
| 31 | + "BR", | |
| 32 | + "DF", | |
| 33 | + "Gama", | |
| 34 | + @juridical_nature, | |
| 35 | + @gov_power, | |
| 36 | + @gov_sphere, | |
| 37 | + "11.222.333/4444-56" | |
| 38 | + ) | |
| 39 | + | |
| 40 | + get "/api/v1/gov_user/institutions?#{params.to_query}" | |
| 41 | + json = JSON.parse(last_response.body) | |
| 42 | + assert_equivalent [@institution.id, @institution1.id], json['institutions'].map {|c| c['id']} | |
| 43 | + end | |
| 44 | + | |
| 45 | + should 'get institution by id' do | |
| 46 | + get "/api/v1/gov_user/institutions/#{@institution.id}?#{params.to_query}" | |
| 47 | + json = JSON.parse(last_response.body) | |
| 48 | + assert_equal @institution.id, json["institution"]["id"] | |
| 49 | + end | |
| 50 | + | |
| 51 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/api.rb
| ... | ... | @@ -9,13 +9,13 @@ class SoftwareCommunitiesPlugin::API < Grape::API |
| 9 | 9 | get do |
| 10 | 10 | authenticate! |
| 11 | 11 | softwares = select_filtered_collection_of(environment,'communities',params).joins(:software_info) |
| 12 | - present softwares, :with => Entities::SoftwareCommunity | |
| 12 | + present softwares.map{|o|o.software_info}, :with => Entities::SoftwareInfo | |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | get ':id' do |
| 16 | 16 | authenticate! |
| 17 | 17 | software = SoftwareInfo.find_by_id(params[:id]) |
| 18 | - present software.community, :with => Entities::SoftwareCommunity | |
| 18 | + present software, :with => Entities::SoftwareInfo | |
| 19 | 19 | end |
| 20 | 20 | |
| 21 | 21 | end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/api_entities.rb
| 1 | 1 | module Entities |
| 2 | 2 | class SoftwareInfo < Noosfero::API::Entity |
| 3 | - expose :id, :finality, :repository_link, :public_software | |
| 4 | - end | |
| 5 | - | |
| 6 | - class SoftwareCommunity < Noosfero::API::Entity | |
| 7 | - root 'softwares', 'software' | |
| 8 | - expose :community, :using => Noosfero::API::Entities::Community do |community, options| | |
| 9 | - community | |
| 3 | + root 'software_infos', 'software_info' | |
| 4 | + expose :id, :finality, :repository_link, :public_software, :acronym, :objectives, | |
| 5 | + :features,:license_info, :software_languages, :software_databases, :operating_system_names | |
| 6 | + expose :community_id do |software_info,options| | |
| 7 | + software_info.community.id | |
| 10 | 8 | end |
| 11 | - expose :software_info, :using => SoftwareInfo | |
| 12 | 9 | end |
| 13 | - | |
| 14 | 10 | end | ... | ... |
src/noosfero-spb/software_communities/test/unit/api_test.rb
| ... | ... | @@ -17,7 +17,7 @@ class SoftwareCommunitiesApiTest < ActiveSupport::TestCase |
| 17 | 17 | |
| 18 | 18 | get "/api/v1/software_communities?#{params.to_query}" |
| 19 | 19 | json = JSON.parse(last_response.body) |
| 20 | - assert_equivalent [@software_info.id, @software_info2.id], json['softwares'].map {|c| c['software_info']['id']} | |
| 20 | + assert_equivalent [@software_info.id, @software_info2.id], json['software_infos'].map {|c| c['id']} | |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | should 'get software by id' do |
| ... | ... | @@ -25,7 +25,7 @@ class SoftwareCommunitiesApiTest < ActiveSupport::TestCase |
| 25 | 25 | get "/api/v1/software_communities/#{@software_info.id}?#{params.to_query}" |
| 26 | 26 | |
| 27 | 27 | json = JSON.parse(last_response.body) |
| 28 | - assert_equal @software_info.id, json["software"]['software_info']["id"] | |
| 28 | + assert_equal @software_info.id, json["software_info"]["id"] | |
| 29 | 29 | end |
| 30 | 30 | |
| 31 | 31 | end | ... | ... |