Skip to content

Commit

Permalink
Merge c43a7f9 into c050930
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo committed Dec 13, 2019
2 parents c050930 + c43a7f9 commit b21b335
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CatalogController < ApplicationController

attr_accessor :poh

# POST /catalog
# POST /v1/catalog
def create
@poh = PreservedObjectHandler.new(bare_druid, incoming_version, incoming_size, moab_storage_root)
poh.create(checksums_validated)
Expand All @@ -25,7 +25,7 @@ def create
render status: status_code, json: poh.results.to_json
end

# PATCH /catalog/:id
# PATCH /v1/catalog/:id
# User can only update a partial record (application controls what can be updated)
def update
@poh = PreservedObjectHandler.new(bare_druid, incoming_version, incoming_size, moab_storage_root)
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
# (Note: methods will eventually be ported from sdr-services-app)
class ObjectsController < ApplicationController
# return the PreservedObject model for the druid (supplied with druid: prefix)
# GET /objects/:druid
# GET /v1/objects/:druid
def show
render json: PreservedObject.find_by!(druid: druid).to_json
end

# return a specific file from the Moab
# GET /objects/:druid/file?category=manifest&filepath=signatureCatalog.xml
# GET /v1/objects/:druid/file?category=manifest&filepath=signatureCatalog.xml
# useful params:
# - category (content|manifest|metadata)
# - filepath path of file, relative to category directory
Expand All @@ -38,14 +38,14 @@ def file
end

# return the checksums and filesize for a single druid (supplied with druid: prefix)
# GET /objects/:druid/checksum
# GET /v1/objects/:druid/checksum
def checksum
render json: content_files_checksums(druid).to_json
end

# return the checksums and filesize for a list of druids (supplied with druid: prefix)
# note: this is deliberately allowed to be a POST to allow for a large number of druids to be passed in
# GET OR POST /objects/checksums?druids[]=druid1&druids[]=druid2&druids[]=druid3
# GET OR POST /v1/objects/checksums?druids[]=druid1&druids[]=druid2&druids[]=druid3
def checksums
unless normalized_druids.present?
render(plain: "400 bad request - druids param must be populated", status: :bad_request)
Expand Down
36 changes: 23 additions & 13 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@
require 'resque/server'

Rails.application.routes.draw do
resources :catalog, param: :druid, only: %i[create update]
mount Resque::Server.new,
at: '/resque',
constraints: ->(req) { Settings.resque_dashboard_hostnames.include?(req.host) }

resources :objects, only: %i[show] do
member do
get 'checksum'
get 'file', format: false # no need to add extension to url
post 'content_diff'
end
collection do
match 'checksums', via: %i[get post]
scope 'v1' do
resources :catalog, param: :druid, only: %i[create update]

resources :objects, only: %i[show] do
member do
get 'checksum'
get 'file', format: false # no need to add extension to url
post 'content_diff'
end
collection do
match 'checksums', via: %i[get post]
end
end
end

mount Resque::Server.new, at: '/resque',
constraints: ->(req) { Settings.resque_dashboard_hostnames.include?(req.host) }

# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
# TODO: Remove these when all clients are using the version-scoped routes above
post '/catalog', to: redirect('/v1/catalog')
match '/catalog/:druid', to: redirect('/v1/catalog/%{druid}'), via: %i[patch put]
get '/objects/:id/checksum', to: redirect('/v1/objects/%{id}/checksum')
get '/objects/:id/file', to: redirect('/v1/objects/%{id}/file')
post '/objects/:id/content_diff', to: redirect('/v1/objects/%{id}/content_diff')
match '/objects/checksums', to: redirect('/v1/objects/checksums'), via: %i[get post]
get '/objects/:id', to: redirect('/v1/objects/%{id}')
end
7 changes: 0 additions & 7 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,4 @@
end
end
end

describe 'Routing' do
let(:druid) { "xx000xx0000" }

it { is_expected.to route(:post, '/catalog').to(controller: :catalog, action: :create) }
it { is_expected.to route(:patch, "/catalog/#{druid}").to(controller: :catalog, action: :update, druid: druid) }
end
end
31 changes: 31 additions & 0 deletions spec/requests/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe CatalogController, type: :request do
let(:druid) { 'druid:bj102hs9687' }

describe 'POST /catalog' do
it 'redirects to /v1/catalog' do
post '/catalog'
expect(response).to have_http_status(:moved_permanently)
expect(response).to redirect_to(catalog_index_url)
end
end

describe 'PUT /catalog/:druid' do
it 'redirects to /v1/catalog/:druid' do
put "/catalog/#{druid}"
expect(response).to have_http_status(:moved_permanently)
expect(response).to redirect_to(catalog_url(druid))
end
end

describe 'PATCH /catalog/:druid' do
it 'redirects to /v1/catalog/:druid' do
patch "/catalog/#{druid}"
expect(response).to have_http_status(:moved_permanently)
expect(response).to redirect_to(catalog_url(druid))
end
end
end

0 comments on commit b21b335

Please sign in to comment.