-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/release-1.8.0'
- Loading branch information
Showing
25 changed files
with
641 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
class Api::V1::EuDecisionsController < ApplicationController | ||
|
||
# makes params available to the ActiveModel::Serializers | ||
serialization_scope :view_context | ||
|
||
def index | ||
@eu_decisions = eu_decision_search(sanitized_params) | ||
render :json => @eu_decisions, | ||
:each_serializer => CaptiveBreeding::EuDecisionSerializer | ||
end | ||
|
||
private | ||
|
||
def permitted_params | ||
params.permit(taxon_concept_ids: [], geo_entity_ids: []) | ||
end | ||
|
||
def eu_decision_search(params) | ||
list = EuDecision.from('api_eu_decisions_view eu_decisions'). | ||
select(eu_decision_select_attrs). | ||
joins('LEFT JOIN eu_suspensions_applicability_view v ON eu_decisions.id = v.id'). | ||
order(<<-SQL | ||
geo_entity_en->>'name' ASC, | ||
start_date DESC | ||
SQL | ||
) | ||
|
||
list = list.where("eu_decisions.taxon_concept_id IN (?)", params['taxon_concept_ids']) if params['taxon_concept_ids'].present? | ||
list = list.where("eu_decisions.geo_entity_id IN (?)", params['geo_entity_ids']) if params['geo_entity_ids'].present? | ||
|
||
list.all | ||
end | ||
|
||
def eu_decision_select_attrs | ||
string = %{ | ||
eu_decisions.notes, | ||
eu_decisions.start_date, | ||
v.original_start_date_formatted, | ||
eu_decisions.is_current, | ||
eu_decisions.geo_entity_id, | ||
eu_decisions.start_event_id, | ||
eu_decisions.term_id, | ||
eu_decisions.source_id, | ||
eu_decisions.eu_decision_type_id, | ||
eu_decisions.term_id, | ||
eu_decisions.source_id, | ||
eu_decisions.nomenclature_note_en, | ||
eu_decisions.nomenclature_note_fr, | ||
eu_decisions.nomenclature_note_es, | ||
eu_decision_type, | ||
srg_history, | ||
start_event, | ||
end_event, | ||
geo_entity_en, | ||
taxon_concept, | ||
term_en, | ||
source_en | ||
} | ||
current_user ? "#{string},\n private_url" : string | ||
end | ||
|
||
def sanitized_params | ||
filters = permitted_params.inject({}) do |h, (k,v)| | ||
h[k] = v.reject(&:empty?).map!(&:to_i) | ||
h | ||
end | ||
filters | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/serializers/captive_breeding/eu_decision_serializer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class CaptiveBreeding::EuDecisionSerializer < ActiveModel::Serializer | ||
attributes :taxon_concept, :notes, { :start_date_formatted => :start_date }, | ||
:is_current, :nomenclature_note_en, :nomenclature_note_fr, | ||
:nomenclature_note_es, | ||
:eu_decision_type, | ||
:srg_history, | ||
:geo_entity, | ||
:start_event, | ||
:source, | ||
:term, | ||
{ :original_start_date_formatted => :original_start_date }, | ||
:private_url | ||
|
||
def taxon_concept | ||
object['taxon_concept'] | ||
end | ||
|
||
def eu_decision_type | ||
object['eu_decision_type'] | ||
end | ||
|
||
def srg_history | ||
object['srg_history'] | ||
end | ||
|
||
def geo_entity | ||
{ 'id'=> object['geo_entity_id'] }.merge(object['geo_entity_en']) | ||
end | ||
|
||
def start_event | ||
object['start_event'] | ||
end | ||
|
||
def source | ||
object['source_en'] | ||
end | ||
|
||
def term | ||
object['term_en'] | ||
end | ||
|
||
def private_url | ||
scope.current_user ? object['private_url'] : nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20220803152826_add_document_ref_to_eu_decisions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddDocumentRefToEuDecisions < ActiveRecord::Migration | ||
def change | ||
add_reference :eu_decisions, :document, index: true | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
db/migrate/20220819121517_add_intersessional_decisions_to_eu_decisions_view.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class AddIntersessionalDecisionsToEuDecisionsView < ActiveRecord::Migration | ||
def up | ||
execute "DROP VIEW IF EXISTS api_eu_decisions_view" | ||
execute "CREATE VIEW api_eu_decisions_view AS #{view_sql('20220808165846', 'api_eu_decisions_view')}" | ||
|
||
execute "DROP VIEW IF EXISTS eu_decisions_view" | ||
execute "CREATE VIEW eu_decisions_view AS #{view_sql('20220819120523', 'eu_decisions_view')}" | ||
end | ||
|
||
def down | ||
execute "DROP VIEW IF EXISTS api_eu_decisions_view" | ||
execute "CREATE VIEW api_eu_decisions_view AS #{view_sql('20200807121747', 'api_eu_decisions_view')}" | ||
|
||
execute "DROP VIEW IF EXISTS eu_decisions_view" | ||
execute "CREATE VIEW eu_decisions_view AS #{view_sql('20200514150717', 'eu_decisions_view')}" | ||
end | ||
end |
Oops, something went wrong.