Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Add gallery image JSON #767

Merged
merged 3 commits into from Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -24,6 +24,7 @@ gem 'feedjira', '~> 2.0'
gem 'fog', '~> 1.33'
gem 'globalize', '~> 5.0'
gem 'globalize-versioning', github: 'globalize/globalize-versioning'
gem 'jbuilder', '~> 2.6.0'
gem 'lograge'
gem 'logstash-event'
gem 'logstash-logger'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -346,6 +346,9 @@ GEM
inflecto (0.0.2)
ipaddress (0.8.3)
iso-639 (0.2.8)
jbuilder (2.6.1)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
jquery-rails (4.2.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
Expand Down Expand Up @@ -629,6 +632,7 @@ DEPENDENCIES
globalize-versioning!
htmlcompressor (= 0.3)
i18n_data
jbuilder (~> 2.6.0)
localeapp (~> 1.0)
lograge
logstash-event
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/galleries_controller.rb
Expand Up @@ -7,7 +7,7 @@ def index
end

def show
@gallery = Gallery.find_by_slug(params[:id])
@gallery = Gallery.find_by_slug(params[:slug])
@documents = search_api_for_image_metadata(@gallery.images)
end

Expand Down
18 changes: 18 additions & 0 deletions app/controllers/gallery_images_controller.rb
@@ -0,0 +1,18 @@
# frozen_string_literal: true
class GalleryImagesController < ApplicationController
def show
@gallery = Gallery.find_by_slug(params[:gallery_slug])
@image = @gallery.images.where(position: params[:position]).first
@response, @document = fetch(@image.europeana_record_id, api_query_params)

respond_to do |format|
format.json
end
end

protected

def api_query_params
params.slice(:api_url)
end
end
10 changes: 10 additions & 0 deletions app/views/gallery_images/show.json.jbuilder
@@ -0,0 +1,10 @@
# frozen_string_literal: true
json.description render_document_show_field_value(@document, 'proxies.dcDescription')
json.creation_date render_document_show_field_value(@document, 'proxies.dcDate')
json.data_provider render_document_show_field_value(@document, 'aggregations.edmDataProvider')
json.provider render_document_show_field_value(@document, 'aggregations.edmProvider')
json.rights do |rights|
rights.license_CC0
rights.license_url render_document_show_field_value(@document, 'aggregations.edmRights')
end
json.url_collection search_url(q: %(edm_datasetName:"#{render_document_show_field_value(@document, 'edmDatasetName')}"))
6 changes: 4 additions & 2 deletions config/routes.rb
Expand Up @@ -51,8 +51,10 @@
get 'explore/topics', to: 'explore#topics'
get 'explore/periods', to: 'explore#periods'

scope '/explore' do
resources :galleries, only: [:show, :index]
scope 'explore' do
resources :galleries, only: [:show, :index], param: :slug do
resources :gallery_images, only: :show, path: 'images', as: 'images', param: :position
end
end

get 'entities/suggest'
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/galleries_controller_spec.rb
Expand Up @@ -35,17 +35,17 @@
let(:gallery) { Gallery.published.first }

it 'returns http success' do
get :show, locale: 'en', id: gallery.slug
get :show, locale: 'en', slug: gallery.slug
expect(response).to have_http_status(:success)
end

it 'assigns gallery to @gallery' do
get :show, locale: 'en', id: gallery.slug
get :show, locale: 'en', slug: gallery.slug
expect(assigns[:gallery]).to eq(gallery)
end

it 'searches the API for the gallery image metadata' do
get :show, locale: 'en', id: gallery.slug
get :show, locale: 'en', slug: gallery.slug
ids = gallery.images.map(&:europeana_record_id)
api_query = %[europeana_id:("#{ids.join('" OR "')}")]
expect(an_api_search_request.
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/gallery_images_controller_spec.rb
@@ -0,0 +1,31 @@
# frozen_string_literal: true
RSpec.describe GalleryImagesController do
describe '#show' do
context 'when gallery is published' do
let(:gallery) { Gallery.published.first }
let(:image) { gallery.images.first }
let(:params) { { locale: 'en', gallery_slug: gallery.slug, position: image.position, format: 'json' } }

it 'returns http success' do
get :show, params
expect(response).to have_http_status(:success)
end

it 'assigns gallery to @gallery' do
get :show, params
expect(assigns[:gallery]).to eq(gallery)
end

it 'assigns image to @image' do
get :show, params
expect(assigns[:image]).to eq(image)
end

it 'requests image metadata from the record API' do
get :show, params
expect(an_api_record_request_for(image.europeana_record_id)).
to have_been_made.at_least_once
end
end
end
end
6 changes: 6 additions & 0 deletions spec/routing/gallery_images_routing_spec.rb
@@ -0,0 +1,6 @@
# frozen_string_literal: true
RSpec.describe 'routes for the gallery images controller' do
it 'routes GET /en/explore/galleries/high-heels/images/2 to gallery_images#show' do
expect(get('/en/explore/galleries/high-heels/images/2')).to route_to('gallery_images#show', locale: 'en', gallery_slug: 'high-heels', position: '2')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [152/140]

end
end