Skip to content

Commit

Permalink
Merge pull request #668 from datacite/add_provider_relations
Browse files Browse the repository at this point in the history
Add provider relationships to serializer on detail
  • Loading branch information
richardhallett authored Nov 4, 2020
2 parents 8abdfc2 + 42a07dd commit bf5a500
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/serializers/datacite_doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class DataciteDoiSerializer

attributes :doi, :prefix, :suffix, :identifiers, :alternate_identifiers, :creators, :titles, :publisher, :container, :publication_year, :subjects, :contributors, :dates, :language, :types, :related_identifiers, :sizes, :formats, :version, :rights_list, :descriptions, :geo_locations, :funding_references, :xml, :url, :content_url, :metadata_version, :schema_version, :source, :is_active, :state, :reason, :landing_page, :view_count, :views_over_time, :download_count, :downloads_over_time, :reference_count, :citation_count, :citations_over_time, :part_count, :part_of_count, :version_count, :version_of_count, :created, :registered, :published, :updated
attributes :prefix, :suffix, :views_over_time, :downloads_over_time, :citations_over_time, if: Proc.new { |object, params| params && params[:detail] }

belongs_to :client, record_type: :clients
belongs_to :provider, record_type: :providers, if: Proc.new { |object, params| params && params[:detail] }
has_many :media, record_type: :media, id_method_name: :uid, if: Proc.new { |object, params| params && params[:detail] && !params[:is_collection]}
has_many :references, record_type: :dois, serializer: DataciteDoiSerializer, object_method_name: :indexed_references, if: Proc.new { |object, params| params && params[:detail] }
has_many :citations, record_type: :dois, serializer: DataciteDoiSerializer, object_method_name: :indexed_citations, if: Proc.new { |object, params| params && params[:detail] }
Expand Down Expand Up @@ -38,7 +39,7 @@ class DataciteDoiSerializer
if params[:affiliation]
a
else
a["name"]
a["name"]
end
end.compact
c
Expand All @@ -53,7 +54,7 @@ class DataciteDoiSerializer
if params[:affiliation]
a
else
a["name"]
a["name"]
end
end.compact
c
Expand Down
9 changes: 9 additions & 0 deletions spec/requests/datacite_dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@
expect(doi.dig('attributes')).to include('xml')
end
end

it 'returns related provider when detail is enabled', vcr: true do
get '/dois?detail=true', nil, headers

expect(last_response.status).to eq(200)
json['data'].each do |doi|
expect(doi.dig('relationships', 'provider','data','id')).to eq(provider.symbol.downcase)
end
end
end

describe "GET /dois with query", elasticsearch: true do
Expand Down

0 comments on commit bf5a500

Please sign in to comment.