Skip to content

Commit

Permalink
Merge pull request #5103 from sul-dlss/display-withdrawn
Browse files Browse the repository at this point in the history
Display withdrawn attribute on user version index
  • Loading branch information
justinlittman authored Jun 25, 2024
2 parents e92e66a + d5e5631 commit 6269add
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
13 changes: 1 addition & 12 deletions app/controllers/user_versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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) }
render json: { user_versions: repository_object.user_versions.map(&:as_json) }
end

def show
Expand All @@ -15,15 +15,4 @@ def show
rescue RepositoryObjectVersion::NoCocina
json_api_error(status: :not_found, message: 'No Cocina for specified version')
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
8 changes: 8 additions & 0 deletions app/models/user_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ def repository_object_version_is_closed
# Validate that the repository object version is closed
errors.add(:repository_object_version, 'cannot set a user version to an open RepositoryObjectVersion') if repository_object_version.open?
end

def as_json
{
userVersion: version,
version: repository_object_version.version,
withdrawn:
}
end
end
6 changes: 4 additions & 2 deletions spec/requests/user_versions_inventory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
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}]}'
expect(response.parsed_body).to eq('user_versions' => [
{ 'userVersion' => 1, 'version' => 1, 'withdrawn' => false },
{ 'userVersion' => 2, 'version' => 2, 'withdrawn' => false }
])
end
end
end

0 comments on commit 6269add

Please sign in to comment.