Skip to content

Commit 73684c9

Browse files
committed
Add a simple UI/API to search for MARC records by ISBN and return a response of those records grouped by organization
1 parent 9b9ec52 commit 73684c9

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

Diff for: app/controllers/lookup_controller.rb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
##
4+
# Controller to lookup MARC records based on standard numbers (e.g. ISBN)
5+
class LookupController < ApplicationController
6+
skip_authorization_check
7+
8+
def index
9+
return {} if index_params[:isbn].blank?
10+
11+
@response = grouped_marc_records
12+
end
13+
14+
def index_params
15+
params.permit(:isbn)
16+
end
17+
helper_method :index_params
18+
19+
private
20+
21+
def grouped_marc_records
22+
MarcRecord.includes(:organization).where(isbn: index_params[:isbn]).group_by(&:organization).select do |org, _|
23+
can? :read, org
24+
end
25+
end
26+
end

Diff for: app/views/lookup/index.html.erb

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<div class="container">
2+
<div class="d-flex justify-content-between">
3+
<h1>Marc Records</h1>
4+
</div>
5+
<%= link_to "view as JSON", url_for(index_params.merge(format: :json)) %>
6+
7+
<table class="table table-striped organizations">
8+
<thead>
9+
<tr>
10+
<th>marc001</th>
11+
<th>Stream</th>
12+
<th>Download</th>
13+
</tr>
14+
</thead>
15+
<tbody>
16+
<% @response.each do |organization, marc_records| %>
17+
<tr>
18+
<td colspan="3" class="bg-info font-weight-bold text-white"><%= organization.name %></td>
19+
</tr>
20+
21+
<% marc_records.each do |marc_record| %>
22+
<tr>
23+
<td><%= marc_record.marc001 %></td>
24+
<td><%= link_to(marc_record.stream.display_name, organization_stream_path(organization, marc_record.stream)) %></td>
25+
<td><%= link_to('marc21', marc21_organization_marc_record_url(organization, marc_record)) %>, <%= link_to('marcxml', marcxml_organization_marc_record_url(organization, marc_record)) %></td>
26+
</tr>
27+
<% end %>
28+
<% end %>
29+
</tbody>
30+
</table>
31+
</div>

Diff for: app/views/lookup/index.json.jbuilder

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
json.total @response&.values&.sum(&:count) || 0
4+
json.isbn index_params[:isbn]
5+
json.organizations @response do |organization, records|
6+
json.extract! organization, :id, :name, :slug
7+
json.records records do |record|
8+
json.extract! record, :id, :marc001, :bytecount, :length, :checksum
9+
json.url organization_marc_record_url(record.organization, record)
10+
end
11+
end

Diff for: config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
get '/documentation/:id', to: 'pages#show', as: :pages
77
get '/api', to: 'pages#api'
88

9+
resources :lookup, only: :index
910

1011
get 'contact_emails/confirm/:token', to: 'contact_emails#confirm', as: :contact_email_confirmation
1112

0 commit comments

Comments
 (0)