diff --git a/app/controllers/lookup_controller.rb b/app/controllers/lookup_controller.rb new file mode 100644 index 00000000..35674b5c --- /dev/null +++ b/app/controllers/lookup_controller.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +## +# Controller to lookup MARC records based on standard numbers (e.g. ISBN) +class LookupController < ApplicationController + skip_authorization_check + + def index + return {} if index_params[:isbn].blank? + + @response = grouped_marc_records + end + + def index_params + params.permit(:isbn) + end + helper_method :index_params + + private + + def grouped_marc_records + MarcRecord.includes(:organization).where(isbn: index_params[:isbn]).group_by(&:organization).select do |org, _| + can? :read, org + end + end +end diff --git a/app/views/lookup/index.html.erb b/app/views/lookup/index.html.erb new file mode 100644 index 00000000..182c7af3 --- /dev/null +++ b/app/views/lookup/index.html.erb @@ -0,0 +1,31 @@ +
+
+

Marc Records

+
+ <%= link_to "view as JSON", url_for(index_params.merge(format: :json)) %> + + + + + + + + + + + <% @response.each do |organization, marc_records| %> + + + + + <% marc_records.each do |marc_record| %> + + + + + + <% end %> + <% end %> + +
marc001StreamDownload
<%= organization.name %>
<%= marc_record.marc001 %><%= link_to(marc_record.stream.display_name, organization_stream_path(organization, marc_record.stream)) %><%= link_to('marc21', marc21_organization_marc_record_url(organization, marc_record)) %>, <%= link_to('marcxml', marcxml_organization_marc_record_url(organization, marc_record)) %>
+
diff --git a/app/views/lookup/index.json.jbuilder b/app/views/lookup/index.json.jbuilder new file mode 100644 index 00000000..a4b18fe9 --- /dev/null +++ b/app/views/lookup/index.json.jbuilder @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +json.total @response&.values&.sum(&:count) || 0 +json.isbn index_params[:isbn] +json.organizations @response do |organization, records| + json.extract! organization, :id, :name, :slug + json.records records do |record| + json.extract! record, :id, :marc001, :bytecount, :length, :checksum + json.url organization_marc_record_url(record.organization, record) + end +end diff --git a/config/routes.rb b/config/routes.rb index b7bd4063..988f94c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,7 @@ get '/documentation/:id', to: 'pages#show', as: :pages get '/api', to: 'pages#api' + resources :lookup, only: :index get 'contact_emails/confirm/:token', to: 'contact_emails#confirm', as: :contact_email_confirmation