return errors as json, improve handling of nested params
[arvados.git] / app / controllers / orvos / v1 / metadata_controller.rb
index b7916d84d2623b63dea9814645de87353a49ab4d..c1ebf2554b320be6906b84a844c9a93dbecf8f1f 100644 (file)
@@ -1,2 +1,27 @@
-class MetadataController < ApplicationController
+class Orvos::V1::MetadataController < ApplicationController
+  def index
+    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
+    @m = params[:metadatum]
+    if params[:metadatum].class == String
+      @m = uncamelcase_hash_keys(JSON.parse params[:metadatum])
+    end
+    @m = Metadatum.new @m
+    respond_to do |format|
+      if @m.save
+        format.html { redirect_to @m, notice: 'Metadatum was successfully created.' }
+        format.json { render json: @m, status: :created, location: @m }
+      else
+        format.html { render action: "new" }
+        format.json { render json: @m.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
 end