Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protected_areas): added attributes in database to the API. Fixed broken attributes #30

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions api/v3/views/protected_area.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ if @current_user.access_to?(ProtectedArea, :is_green_list)
attribute :is_green_list
end

if @current_user.access_to?(ProtectedArea, :is_oecm)
attribute :is_oecm
end

if @current_user.access_to?(ProtectedArea, :supplementary_info)
attribute :supplementary_info
end

if @current_user.access_to?(ProtectedArea, :conservation_objectives)
attribute :conservation_objectives
end

if @current_user.access_to?(ProtectedArea, :green_list_url)
attribute :green_list_url
end

# Relations
if @current_user.access_to?(ProtectedArea, :countries)
child :countries, object_root: false do
Expand All @@ -49,8 +65,8 @@ if @current_user.access_to?(ProtectedArea, :countries)
end
end

if @current_user.access_to?(ProtectedArea, :sublocations)
child :sublocations, object_root: false do
if @current_user.access_to?(ProtectedArea, :sub_locations)
child :sub_locations, object_root: false do
attributes :id, :english_name
end
end
Expand Down Expand Up @@ -109,3 +125,9 @@ if @current_user.access_to?(ProtectedArea, :pame_evaluations)
end
end
end

if @current_user.access_to?(ProtectedArea, :green_list_status)
child :green_list_status, object_root: false do
attributes :id, :status, :expiry_date
end
end
3 changes: 3 additions & 0 deletions models/green_list_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class GreenListStatus < ActiveRecord::Base
has_one :protected_area
end
9 changes: 8 additions & 1 deletion models/protected_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class ProtectedArea < ActiveRecord::Base
:legal_status, :legal_status_updated_at,
:management_plan, :management_authority,
:governance, :reported_area, :reported_marine_area,
:owner_type, :pame_evaluations
:owner_type, :pame_evaluations, :sub_locations,
:green_list_status, :is_oecm, :supplementary_info,
:conservation_objectives, :green_list_url
]

belongs_to :iucn_category
Expand All @@ -24,6 +26,7 @@ class ProtectedArea < ActiveRecord::Base
belongs_to :governance
belongs_to :no_take_status
belongs_to :management_authority
belongs_to :green_list_status
has_and_belongs_to_many :countries, -> { select(:id, :name, :iso_3) }
has_and_belongs_to_many :sub_locations
has_many :pame_evaluations
Expand Down Expand Up @@ -56,4 +59,8 @@ def self.search params
def link_to_pp
File.join($secrets[:host], self.wdpa_id.to_s)
end

def is_green_list
green_list_status_id.present?
end
end
40 changes: 29 additions & 11 deletions web/views/documentation/protected_areas.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Sample response:
"reported_area": "0.3933",
"management_plan": "Not Reported",
"is_green_list": false,
"is_oecm": false,
"supplementary_info": "Not Applicable",
"conservation_objectives": "Not Applicable",
"green_list_url": null,
"owner_type": "Not Reported",
"countries": [
{
Expand All @@ -79,20 +83,21 @@ Sample response:
"id": "UGA"
}
],
"sub_locations": [],
"iucn_category": {
"id": 8,
"name": "Not Reported"
},
"designation": {
"id": 12,
"id": 13,
"name": "Forest Reserve",
"jurisdiction": {
"id": 1,
"name": "National"
}
},
"no_take_status": {
"id": 11851,
"id": 11293,
"name": "Not Applicable",
"area": "0.0"
},
Expand All @@ -109,6 +114,7 @@ Sample response:
"governance_type": "Governance by Government"
},
"pame_evaluations": [],
"green_list_status": null,
"links": {
"protected_planet": "http://protectedplanet.net/40366"
},
Expand Down Expand Up @@ -265,6 +271,10 @@ Sample response:
"reported_area": "484.6",
"management_plan": "Not Reported",
"is_green_list": false,
"is_oecm": false,
"supplementary_info": "Not Applicable",
"conservation_objectives": "Not Applicable",
"green_list_url": null,
"owner_type": "Not Reported",
"countries": [
{
Expand All @@ -273,6 +283,7 @@ Sample response:
"id": "MAR"
}
],
"sub_locations": [],
"iucn_category": {
"id": 10,
"name": "Not Assigned"
Expand All @@ -286,12 +297,12 @@ Sample response:
}
},
"no_take_status": {
"id": 157133,
"id": 148453,
"name": "Not Reported",
"area": "0.0"
},
"legal_status": {
"id": 5,
"id": 6,
"name": "Adopted"
},
"management_authority": {
Expand All @@ -304,19 +315,20 @@ Sample response:
},
"pame_evaluations": [
{
"id": 55317,
"metadata_id": 42,
"url": "Not Reported",
"id": 29653,
"metadata_id": 27,
"url": "Not reported",
"year": 2018,
"methodology": "IMET",
"source": {
"data_title": "List of protected areas assessed with the Integrated Management Effectiveness Tool (IMET)",
"resp_party": "European Commission",
"data_title": "JRC IMET information",
"resp_party": "JRC",
"year": 2019,
"language": "English"
}
}
],
"green_list_status": null,
"links": {
"protected_planet": "http://protectedplanet.net/555547509"
},
Expand Down Expand Up @@ -391,6 +403,10 @@ Sample response:
"reported_area": "0.3933",
"management_plan": "Not Reported",
"is_green_list": false,
"is_oecm": false,
"supplementary_info": "Not Applicable",
"conservation_objectives": "Not Applicable",
"green_list_url": null,
"owner_type": "Not Reported",
"countries": [
{
Expand All @@ -399,20 +415,21 @@ Sample response:
"id": "UGA"
}
],
"sub_locations": [],
"iucn_category": {
"id": 8,
"name": "Not Reported"
},
"designation": {
"id": 12,
"id": 13,
"name": "Forest Reserve",
"jurisdiction": {
"id": 1,
"name": "National"
}
},
"no_take_status": {
"id": 11851,
"id": 11293,
"name": "Not Applicable",
"area": "0.0"
},
Expand All @@ -429,6 +446,7 @@ Sample response:
"governance_type": "Governance by Government"
},
"pame_evaluations": [],
"green_list_status": null,
"links": {
"protected_planet": "http://protectedplanet.net/40366"
},
Expand Down