Skip to content

Commit

Permalink
Merge pull request #1156 from Vizzuality/develop
Browse files Browse the repository at this point in the history
Hotfix: fix indonesia ports layer
  • Loading branch information
sorodrigo authored Nov 11, 2019
2 parents a40a2bd + fc36280 commit ebda1ae
Show file tree
Hide file tree
Showing 33 changed files with 2,328 additions and 314 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gem 'scenic'
gem 'pg_csv'
gem 'pg_search'
gem 'rubyzip'
gem 'puma', '~> 4.2'
gem 'puma', '~> 4.3'
gem 'dotenv-rails', '~> 2.7'
gem 'active_model_serializers', '~> 0.10.10'
gem 'kaminari'
Expand Down
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ GEM
public_suffix (>= 2.0.2, < 4.0)
airbrussh (1.4.0)
sshkit (>= 1.6.1, != 1.7.0)
annotate (3.0.2)
annotate (3.0.3)
activerecord (>= 3.2, < 7.0)
rake (>= 10.4, < 13.0)
appsignal (2.9.16)
rake (>= 10.4, < 14.0)
appsignal (2.9.17)
rack
arbre (1.2.1)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -246,15 +246,15 @@ GEM
mimemagic (0.3.3)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.12.2)
minitest (5.13.0)
msgpack (1.3.1)
multipart-post (2.0.0)
naught (1.1.0)
net-scp (2.0.0)
net-ssh (>= 2.6.5, < 6.0.0)
net-ssh (5.2.0)
newrelic_rpm (6.7.0.359)
nio4r (2.3.1)
nio4r (2.5.2)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
oj (3.9.2)
Expand All @@ -277,7 +277,7 @@ GEM
polyamorous (2.3.0)
activerecord (>= 5.0)
public_suffix (3.0.3)
puma (4.2.1)
puma (4.3.0)
nio4r (~> 2.0)
rack (2.0.7)
rack-cors (1.0.3)
Expand Down Expand Up @@ -314,7 +314,7 @@ GEM
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rainbow (3.0.0)
rake (12.3.3)
rake (13.0.0)
ransack (2.3.0)
actionpack (>= 5.0)
activerecord (>= 5.0)
Expand Down Expand Up @@ -498,7 +498,7 @@ DEPENDENCIES
pg (~> 0.18)
pg_csv
pg_search
puma (~> 4.2)
puma (~> 4.3)
rack-cors (~> 1.0)
rails (~> 5.2.3)
rails-controller-testing
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/api/public/commodities_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Api
module Public
class CommoditiesController < ApiController
include Api::V3::ParamHelpers

skip_before_action :load_context
before_action :set_collection, only: [:index]

def index
render json: @collection,
each_serializer: Api::Public::CommoditySerializer
end

private

def set_collection
@collection = Api::Public::FilterCommodities.new(filter_params).call
end

def filter_params
{
countries_ids: cs_string_to_int_array(params[:countries_ids]),
commodities_ids: cs_string_to_int_array(params[:commodities_ids]),
include: params[:include]
}
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module Api
module V3
module Public
class CountriesController < ApiController
include Api::V3::ParamHelpers

skip_before_action :load_context
before_action :set_collection, only: %i[index]
before_action :set_collection, only: [:index]

def index
render json: @collection,
each_serializer: Api::V3::Dashboards::CountrySerializer
each_serializer: Api::Public::CountrySerializer
end

private

def set_collection
@collection = Api::V3::FilterCountries.new(filter_params).call
@collection = Api::Public::FilterCountries.new(filter_params).call
end

def filter_params
Expand Down
27 changes: 27 additions & 0 deletions app/controllers/api/public/nodes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Api
module Public
class NodesController < ApiController
skip_before_action :load_context

def data
ensure_required_param_present(:id)
ensure_required_param_present(:year)

@result = Api::Public::Node::Filter.new(filter_params).call

render json: @result,
root: 'data',
serializer: Api::Public::Node::NodeSerializer
end

private

def filter_params
{
id: params[:id],
year: params[:year]
}
end
end
end
end
20 changes: 0 additions & 20 deletions app/controllers/api/v3/commodities_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
module Api
module V3
class CommoditiesController < ApiController
include Api::V3::ParamHelpers

skip_before_action :load_context
before_action :load_commodity, only: [:countries_facts]
before_action :set_collection, only: [:index]

def index
render json: @collection,
each_serializer: Api::V3::Dashboards::CommoditySerializer
end

def countries_facts
facts = Api::V3::SupplyChainCountriesFacts.new(
Expand All @@ -31,18 +23,6 @@ def countries_facts

private

def set_collection
@collection = Api::V3::FilterCommodities.new(filter_params).call
end

def filter_params
{
countries_ids: cs_string_to_int_array(params[:countries_ids]),
commodities_ids: cs_string_to_int_array(params[:commodities_ids]),
include: params[:include]
}
end

def load_commodity
@commodity = Api::V3::Commodity.find(params[:id])
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v3/dashboards/commodities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def index

render json: @collection,
root: 'data',
each_serializer: Api::V3::Dashboards::CommoditySerializer
each_serializer: Api::Public::CommoditySerializer
end

def search
Expand All @@ -20,7 +20,7 @@ def search

render json: @collection,
root: 'data',
each_serializer: Api::V3::Dashboards::CommoditySerializer
each_serializer: Api::Public::CommoditySerializer
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v3/dashboards/countries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def index

render json: @collection,
root: 'data',
each_serializer: Api::V3::Dashboards::CountrySerializer
each_serializer: Api::Public::CountrySerializer
end

def search
Expand All @@ -20,7 +20,7 @@ def search

render json: @collection,
root: 'data',
each_serializer: Api::V3::Dashboards::CountrySerializer
each_serializer: Api::Public::CountrySerializer
end

private
Expand Down
12 changes: 12 additions & 0 deletions app/serializers/api/public/commodity_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Api
module Public
class CommoditySerializer < ActiveModel::Serializer
attributes :id, :name
attribute :country_ids, if: :include_countries?

def include_countries?
@instance_options[:include_countries]
end
end
end
end
7 changes: 7 additions & 0 deletions app/serializers/api/public/country_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Api
module Public
class CountrySerializer < ActiveModel::Serializer
attributes :id, :name
end
end
end
14 changes: 14 additions & 0 deletions app/serializers/api/public/node/node_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Api
module Public
module Node
class NodeSerializer < ActiveModel::Serializer
attributes :name,
:node_type,
:geo_id,
:availability,
:node_attributes,
:flow_attributes
end
end
end
end
14 changes: 0 additions & 14 deletions app/serializers/api/v3/dashboards/commodity_serializer.rb

This file was deleted.

9 changes: 0 additions & 9 deletions app/serializers/api/v3/dashboards/country_serializer.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/serializers/api/v3/dashboards/template_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class TemplateSerializer < ActiveModel::Serializer
key: :destinations

has_many :commodities,
serializer: Api::V3::Dashboards::CommoditySerializer,
serializer: Api::Public::CommoditySerializer,
key: :commodities

has_many :countries,
serializer: Api::V3::Dashboards::CountrySerializer,
serializer: Api::Public::CountrySerializer,
key: :countries

attribute :image_url do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Api
module V3
module Public
class FilterCommodities
def initialize(params)
@meta = {}
Expand Down Expand Up @@ -40,7 +40,7 @@ def include_countries
country_ids = @query.map(&:country_ids).flatten.uniq
countries = Api::V3::Country.where(id: country_ids)
@meta[:countries] = ActiveModel::Serializer::CollectionSerializer.new(
countries, serializer: Api::V3::Dashboards::CountrySerializer
countries, serializer: Api::Public::CountrySerializer
).as_json
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Api
module V3
module Public
class FilterCountries
def initialize(params)
@meta = {}
Expand Down Expand Up @@ -40,7 +40,7 @@ def include_commodities
commodity_ids = @query.map(&:commodity_ids).flatten.uniq
commodities = Api::V3::Commodity.where(id: commodity_ids)
@meta[:commodities] = ActiveModel::Serializer::CollectionSerializer.new(
commodities, serializer: Api::V3::Dashboards::CommoditySerializer
commodities, serializer: Api::Public::CommoditySerializer
).as_json
end
end
Expand Down
Loading

0 comments on commit ebda1ae

Please sign in to comment.