Implement viewpoints/:uuid/snapshot

pull/7895/head
Oliver Günther 5 years ago
parent 8e5e4c1433
commit 64b4f3fb9f
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 4
      modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb
  2. 16
      modules/bcf/app/controllers/bcf/api/v2_1/viewpoints_api.rb
  3. 10
      modules/bcf/spec/factories/bcf_viewpoint_factory.rb
  4. 28
      modules/bcf/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb

@ -47,9 +47,9 @@ module Bcf::API::V2_1
scope: -> { topics })
.mount
route_param :uuid, regexp: /\A[a-f0-9\-]+\z/ do
route_param :topic_uuid, regexp: /\A[a-f0-9\-]+\z/ do
after_validation do
@issue = topics.find_by_uuid!(params[:uuid])
@issue = topics.find_by_uuid!(params[:topic_uuid])
end
get &::Bcf::API::V2_1::Endpoints::Show

@ -37,15 +37,27 @@ module Bcf::API::V2_1
scope: -> { @issue.viewpoints })
.mount
route_param :uuid, regexp: /\A[a-f0-9\-]+\z/ do
route_param :viewpoint_uuid, regexp: /\A[a-f0-9\-]+\z/ do
after_validation do
@viewpoint = @issue.viewpoints.find_by_uuid!(params[:uuid])
@viewpoint = @issue.viewpoints.find_by_uuid!(params[:viewpoint_uuid])
end
get &::Bcf::API::V2_1::Endpoints::Show
.new(model: Bcf::Viewpoint,
api_name: 'Viewpoints')
.mount
namespace :snapshot do
helpers ::API::Helpers::AttachmentRenderer
get do
if snapshot = @viewpoint.snapshot
respond_with_attachment snapshot
else
raise ActiveRecord::RecordNotFound
end
end
end
end
end
end

@ -156,8 +156,14 @@ FactoryBot.define do
MARKUP
end
after(:create) do |viewpoint|
create(:bcf_viewpoint_attachment, container: viewpoint)
transient do
snapshot { nil }
end
after(:create) do |viewpoint, evaluator|
unless evaluator.snapshot == false
create(:bcf_viewpoint_attachment, container: viewpoint)
end
end
end
end

@ -103,4 +103,32 @@ describe 'BCF 2.1 viewpoints resource', type: :request, content_type: :json, wit
it_behaves_like 'bcf api not found response'
end
end
describe 'GET /api/bcf/2.1/projects/:project_id/topics/:uuid/viewpoints/:uuid/snapshot' do
let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/viewpoints/#{viewpoint.uuid}/snapshot" }
let(:current_user) { view_only_user }
context 'when snapshot present' do
before do
login_as(current_user)
bcf_issue
get path
end
it 'responds with the attachment' do
expect(subject.status).to eq 200
expect(subject.headers['Content-Type']).to eq 'image/jpeg'
end
end
context 'when snapshot not present' do
before do
login_as(current_user)
viewpoint.snapshot.destroy
get path
end
it_behaves_like 'bcf api not found response'
end
end
end

Loading…
Cancel
Save