On 10/05/2011 10:17 AM, mtaylor(a)redhat.com wrote:
From: Martyn Taylor<mtaylor(a)redhat.com>
---
.../controllers/api/provider_images_controller.rb | 12 ++++++++++--
.../controllers/api/target_images_controller.rb | 17 +++++++++++++++++
src/app/views/api/provider_images/_image.xml.haml | 14 +++++++++-----
src/app/views/api/target_images/_image.xml.haml | 17 ++++++++++-------
4 files changed, 46 insertions(+), 14 deletions(-)
diff --git a/src/app/controllers/api/provider_images_controller.rb
b/src/app/controllers/api/provider_images_controller.rb
index e5426d7..16e3e1a 100644
--- a/src/app/controllers/api/provider_images_controller.rb
+++ b/src/app/controllers/api/provider_images_controller.rb
@@ -37,7 +37,15 @@ module Api
if @image
respond_with(@image)
else
- render :nothing => true, :status => 404
+ status = Aeolus::Image::Factory::ProviderImage.status(id)
+ if !status.nil?
Is the explicit `nil?` check necessary here? I think this should be enough:
if status
...
else
render :text => "Resource Not Found", :status => 404
end
+ @image = Aeolus::Image::Factory::ProviderImage.new(:id
=> id,
+ :href =>
api_provider_image_url(id),
+ :status => status)
+ respond_with(@image)
+ else
+ render :text => "Resource Not Found", :status => 404
+ end
end
end
@@ -77,4 +85,4 @@ module Api
end
end
end
-end
\ No newline at end of file
+end
diff --git a/src/app/controllers/api/target_images_controller.rb
b/src/app/controllers/api/target_images_controller.rb
index 99a946f..0a4945a 100644
--- a/src/app/controllers/api/target_images_controller.rb
+++ b/src/app/controllers/api/target_images_controller.rb
@@ -41,5 +41,22 @@ module Api
end
end
+ def show
+ id = params[:id]
+ @image = Aeolus::Image::Warehouse::TargetImage.find(id)
+ if @image
+ respond_with(@image)
+ else
+ status = Aeolus::Image::Factory::TargetImage.status(id)
+ if !status.nil?
Same here ^, `if status` may be better.
+ @image = Aeolus::Image::Factory::TargetImage.new(:id =>
id,
+ :href =>
api_target_image_url(id),
+ :status => status)
+ respond_with(@image)
+ else
+ render :text => "Resource Not Found", :status => 404
+ end
+ end
+ end
end
end
diff --git a/src/app/views/api/provider_images/_image.xml.haml
b/src/app/views/api/provider_images/_image.xml.haml
index ee49143..40ff44f 100644
--- a/src/app/views/api/provider_images/_image.xml.haml
+++ b/src/app/views/api/provider_images/_image.xml.haml
@@ -1,6 +1,10 @@
!!!XML
-%provider_image{:id => image.uuid, :href => api_provider_image_url(image.uuid)
}
- %icicle= image.icicle
- %object_type= image.object_type
- %target_identifier= image.target_identifier
- %target_image{:id => image.target_image.uuid, :href =>
api_target_image_url(image.target_image.uuid)}
+%provider_image{:id => image.id, :href => api_provider_image_url(image.id) }
+ - if @image.respond_to?('status')
+ %status=(a)image.status
+ - else
+ %icicle= image.icicle
+ %object_type= image.object_type
+ %target_identifier= image.target_identifier
+ %status="COMPLETE"
+ %target_image{:id => image.target_image.uuid, :href =>
api_target_image_url(image.target_image.uuid)}
diff --git a/src/app/views/api/target_images/_image.xml.haml
b/src/app/views/api/target_images/_image.xml.haml
index 6616346..894e24a 100644
--- a/src/app/views/api/target_images/_image.xml.haml
+++ b/src/app/views/api/target_images/_image.xml.haml
@@ -1,9 +1,12 @@
!!!XML
%target_image{:id => image.uuid, :href => api_target_image_url(image.uuid) }
- %icicle= image.icicle
- %object_type= image.object_type
- %template= image.template
- %build{:href=>api_build_url(image.build.uuid), :id=>image.build.uuid}
- %provider_images
- - image.provider_images.each do |pimg|
- %provider_image{:id => pimg.uuid, :href =>
api_provider_image_url(pimg.uuid)}
+ - if @image.respond_to?('status')
+ %status=(a)image.status
+ - else
+ %icicle= image.icicle
+ %object_type= image.object_type
+ %template= image.template
+ %build{:href=>api_build_url(image.build.uuid), :id=>image.build.uuid}
+ %provider_images
+ - image.provider_images.each do |pimg|
+ %provider_image{:id => pimg.uuid, :href =>
api_provider_image_url(pimg.uuid)}
Hey Martyn,
Looks good. Unfortunately, some rspec tests are failing with this.
Also 2 small suggestions inline.
Could you please resend with fixed tests?
Thanks,
Thomas
--
No trees were killed to send this message, but a large number of
electrons were terribly inconvenienced.