add "find metadata by target kind + uuid" refs #1236, and generalize some code into...
authorTom Clegg <tom@clinicalfuture.com>
Wed, 9 Jan 2013 02:14:50 +0000 (18:14 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Wed, 9 Jan 2013 02:14:50 +0000 (18:14 -0800)
app/controllers/application_controller.rb
app/controllers/orvos/v1/metadata_controller.rb
config/routes.rb

index 9c29f16536071fca32766135935aaf17b2d67a94..612a8896bdd2a926a20131af2e47ef17e1064e8e 100644 (file)
@@ -1,7 +1,16 @@
 class ApplicationController < ActionController::Base
   protect_from_forgery
   before_filter :uncamelcase_params_hash_keys
-  before_filter :find_object_by_uuid
+  before_filter :find_object_by_uuid, :except => :index
+
+  def index
+    @objects ||= model_class.all
+    render_list
+  end
+
+  def show
+    render json: @object
+  end
 
   protected
 
@@ -35,4 +44,16 @@ class ApplicationController < ActionController::Base
     end
     h
   end
+
+  def render_list
+    @object_list = {
+      :kind  => "orvos##{model_class.to_s.camelize(:down)}List",
+      :etag => "",
+      :self_link => "",
+      :next_page_token => "",
+      :next_link => "",
+      :items => @objects.map { |x| x }
+    }
+    render json: @object_list
+  end
 end
index 635378c083876f43ffec935fd6a4b656409b5f94..c1ebf2554b320be6906b84a844c9a93dbecf8f1f 100644 (file)
@@ -1,25 +1,10 @@
 class Orvos::V1::MetadataController < ApplicationController
   def index
-    @metadata = Collection.all
-    @metadatumlist = {
-      :kind  => "orvos#metadatumList",
-      :etag => "",
-      :self_link => "",
-      :next_page_token => "",
-      :next_link => "",
-      :items => @metadata.map { |x| x }
-    }
-    respond_to do |format|
-      format.json { render json: @metadatumlist }
-    end
-  end
-
-  def show
-    @m = Metadatum.find(params[:id])
-
-    respond_to do |format|
-      format.json { render json: @m }
+    if params[:target_kind] and params[:target_uuid]
+      @objects = Metadatum.where('target_kind=? and target_uuid=?',
+                                 params[:target_kind], params[:target_uuid])
     end
+    super
   end
 
   def create
@@ -38,4 +23,5 @@ class Orvos::V1::MetadataController < ApplicationController
       end
     end
   end
+
 end
index 0cfeac851bf814a32516d2ccbf40cb914b3c90a9..9318be5a67af98b1061c8c515f1d347e03a57720 100644 (file)
@@ -66,6 +66,7 @@ Server::Application.routes.draw do
       resources :metadata
       resources :nodes
       match '/nodes/:uuid/ping' => 'nodes#ping', :as => :ping_node
+      match '/metadata/:target_kind/:target_uuid' => 'metadata#index'
     end
   end