-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4994 from sul-dlss/t4993-user_version_index
Adds user version index endpoint.
- Loading branch information
Showing
5 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# Controller for user versions | ||
class UserVersionsController < ApplicationController | ||
def index | ||
repository_object = RepositoryObject.find_by!(external_identifier: params[:object_id]) | ||
|
||
render json: { user_versions: user_versions_content(repository_object.user_versions) } | ||
end | ||
|
||
private | ||
|
||
def user_versions_content(user_versions) | ||
user_versions.map do |user_version| | ||
{ | ||
userVersion: user_version.version, | ||
version: user_version.repository_object_version.version | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'User versions' do | ||
let(:druid) { 'druid:mx123qw2323' } | ||
|
||
context 'when found' do | ||
before do | ||
repository_object = create(:repository_object, :closed, external_identifier: druid) | ||
create(:repository_object_version, repository_object:, version: 2, closed_at: Time.zone.now) | ||
create(:user_version, version: 1, repository_object_version: repository_object.versions.first) | ||
create(:user_version, version: 2, repository_object_version: repository_object.versions.last) | ||
end | ||
|
||
it 'returns a 200' do | ||
get "/v1/objects/#{druid}/user_versions", | ||
headers: { 'Authorization' => "Bearer #{jwt}" } | ||
|
||
expect(response).to have_http_status(:ok) | ||
expect(response.body).to eq '{"user_versions":[{"userVersion":1,"version":1},' \ | ||
'{"userVersion":2,"version":2}]}' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters