un-serialize data passed by google api client
[arvados.git] / app / controllers / orvos / v1 / collections_controller.rb
1 class Orvos::V1::CollectionsController < ApplicationController
2   # GET /collections
3   # GET /collections.json
4   def index
5     @collections = Collection.all
6
7     @collectionlist = {
8       :kind  => "orvos#collectionList",
9       :etag => "",
10       :self_link => "",
11       :next_page_token => "",
12       :next_link => "",
13       :items => @collections.map { |collection| collection }
14     }
15     respond_to do |format|
16       format.json { render json: @collectionlist }
17     end
18   end
19
20   # GET /collections/1
21   # GET /collections/1.json
22   def show
23     @collection = Collection.find(params[:id])
24
25     respond_to do |format|
26       format.html # show.html.erb
27       format.json { render json: @collection }
28     end
29   end
30
31   # GET /collections/new
32   # GET /collections/new.json
33   def new
34     @collection = Collection.new
35
36     respond_to do |format|
37       format.html # new.html.erb
38       format.json { render json: @collection }
39     end
40   end
41
42   # GET /collections/1/edit
43   def edit
44     @collection = Collection.find(params[:id])
45   end
46
47   # POST /collections
48   # POST /collections.json
49   def create
50     if params[:collection].class == String
51       @collection = Collection.new(JSON.parse(params[:collection]))
52     else
53       @collection = Collection.new(params[:collection])
54     end
55
56     respond_to do |format|
57       if @collection.save
58         format.html { redirect_to @collection, notice: 'Collection was successfully created.' }
59         format.json { render json: @collection, status: :created, location: @collection }
60       else
61         format.html { render action: "new" }
62         format.json { render json: @collection.errors, status: :unprocessable_entity }
63       end
64     end
65   end
66
67   # PUT /collections/1
68   # PUT /collections/1.json
69   def update
70     @collection = Collection.find(params[:id])
71
72     respond_to do |format|
73       if @collection.update_attributes(params[:collection])
74         format.html { redirect_to @collection, notice: 'Collection was successfully updated.' }
75         format.json { head :ok }
76       else
77         format.html { render action: "edit" }
78         format.json { render json: @collection.errors, status: :unprocessable_entity }
79       end
80     end
81   end
82
83   # DELETE /collections/1
84   # DELETE /collections/1.json
85   def destroy
86     @collection = Collection.find(params[:id])
87     @collection.destroy
88
89     respond_to do |format|
90       format.html { redirect_to collections_url }
91       format.json { head :ok }
92     end
93   end
94 end