Skip to content

Commit

Permalink
Merge pull request #684 from sul-dlss/sitemap-list
Browse files Browse the repository at this point in the history
Add API for getting sitemap data
  • Loading branch information
jcoyne authored Apr 16, 2024
2 parents c247079 + 06fb65e commit e8630ec
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 1 deletion.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,43 @@ The `/collections/:druid/purls` endpoint a listing of Purls for a specific colle
}
```

### Released items

#### `/released/:tag`

`GET /released/:tag`

##### Parameters

| Name | Located In | Description | Required | Schema | Default |
| ---------- | ---------- | ------------------------------------------ | -------- | ------------------------------- | ------- |
| `tag` | url | Tag to search for | Yes | string eg(`PURL%20sitemap`) | null |


##### Summary

List the PURLs that should display on the sitemap.

##### Description

This is used by the PURL application to generate a sitemap

##### Example Response

```json
[
{
"druid": "druid:ee111ff2222",
"updated_at": "2016-01-03T00:00:00.000Z",
},
...
{
"druid": "druid:cc111dd2222",
"updated_at": "2016-01-02T00:00:00.000Z",
}
]
```

## Administration

### Reindexing
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/v1/released_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module V1
class ReleasedController < ApplicationController
def show
release_tag = params[:id]
purls = Purl.published
.status('public')
.target(release_tag).pluck(:druid, :updated_at)

render json: purls.map { |(druid, updated_at)| { druid:, updated_at: } }
end
end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
get 'changes'
end

resources :released, only: :show

resources :purls, only: [:destroy], param: :druid do
member do
post '/', action: 'update'
Expand Down
1 change: 1 addition & 0 deletions spec/factories/purl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
sequence :druid do |n|
"druid:zz#{n.to_s * 3}yy#{n.to_s * 4}"
end
published_at { 1.day.ago }
end
end
7 changes: 7 additions & 0 deletions spec/factories/release_tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :release_tag do
purl
name { 'Searchworks' }
release_type { true }
end
end
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!

config.fixture_path = "#{::Rails.root}/test/fixtures"
config.fixture_paths = ["#{::Rails.root}/test/fixtures"]

config.use_transactional_fixtures = true

Expand Down
13 changes: 13 additions & 0 deletions spec/requests/v1/released_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rails_helper'

RSpec.describe V1::ReleasedController do
describe '#show' do
let!(:release_tag) { create(:release_tag, name: "PURL sitemap") }
let(:purl) { release_tag.purl }

it 'returns list of druids' do
get '/released/PURL%20sitemap'
expect(response.parsed_body).to eq [{ 'druid' => purl.druid, 'updated_at' => purl.updated_at.iso8601(3) }]
end
end
end

0 comments on commit e8630ec

Please sign in to comment.