Skip to content

Commit

Permalink
Adds user version index endpoint.
Browse files Browse the repository at this point in the history
closes #4993
  • Loading branch information
justinlittman committed May 17, 2024
1 parent a31dbe8 commit ed7738f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
21 changes: 21 additions & 0 deletions app/controllers/user_versions_controller.rb
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
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
end
end

resources :user_versions, only: [:index]

resources :release_tags, only: [:create, :index]
end
end
Expand Down
40 changes: 39 additions & 1 deletion openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,26 @@ paths:
schema:
type: string
example: "some_sunetid"
"/v1/objects/{object_id}/user_versions":
get:
tags:
- versions
summary: The user version log for this object
operationId: "user_versions#index"
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/UserVersionLog"
parameters:
- name: object_id
in: path
description: ID of object
required: true
schema:
$ref: "#/components/schemas/Druid"
/v1/objects:
post:
tags:
Expand Down Expand Up @@ -3274,6 +3294,24 @@ components:
# environments and deployed environments that use Apache & Passenger
pattern: '^.+(\+(?:%3A|:)\+.+)+$'
example: "Foo+%3A+Bar+%3A+Baz"
UserVersion:
type: object
description: "Information about a user version."
properties:
version:
type: integer
description: the number of the object version
userVersion:
type: integer
description: the number of the user version
UserVersionLog:
type: object
description: "User versions for an object."
properties:
versions:
type: array
items:
$ref: "#/components/schemas/UserVersion"
Version:
type: object
description: "Similar to the version inventory specified by OCFL: https://ocfl.io/draft/spec/#version-inventory"
Expand All @@ -3286,7 +3324,7 @@ components:
description: the number of the version
message:
type: string
description: a message that explans what changed
description: a message that explains what changed
VersionLog:
type: object
description: "Similar to the version inventory specified by OCFL: https://ocfl.io/draft/spec/#version-inventory"
Expand Down
25 changes: 25 additions & 0 deletions spec/requests/user_versions_inventory_spec.rb
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
2 changes: 1 addition & 1 deletion spec/requests/versions_inventory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe 'Release tags' do
RSpec.describe 'Versions' do
let(:druid) { 'druid:mx123qw2323' }

let(:repository_object) { build(:repository_object, **attrs) }
Expand Down

0 comments on commit ed7738f

Please sign in to comment.