OSDN Git Service

Return lectures of given ids which include tasks
[sharp4k/CUTEn.git] / CutenServer / app / controllers / lectures_controller.rb
1 class LecturesController < ApplicationController
2   # GET /lectures
3   # GET /lectures.json
4   def index
5     if params[:ids] and params[:ids].is_a? Array
6       @lectures = Lecture.where :id => params[:ids]
7       render json: @lectures.as_json(:methods => [:tasks])
8     else
9       @lectures = Lecture.all
10       render json: @lectures
11     end
12   end
13
14   # GET /lectures/1
15   # GET /lectures/1.json
16   def show
17     @lecture = Lecture.find(params[:id])
18
19     render json: @lecture
20   end
21
22   # GET /lectures/new
23   # GET /lectures/new.json
24   def new
25     @lecture = Lecture.new
26
27     render json: @lecture
28   end
29
30   # POST /lectures
31   # POST /lectures.json
32   def create
33     @lecture = Lecture.new(params[:lecture])
34
35     if @lecture.save
36       render json: @lecture, status: :created, location: @lecture
37     else
38       render json: @lecture.errors, status: :unprocessable_entity
39     end
40   end
41
42   # PATCH/PUT /lectures/1
43   # PATCH/PUT /lectures/1.json
44   def update
45     @lecture = Lecture.find(params[:id])
46
47     if @lecture.update_attributes(params[:lecture])
48       head :no_content
49     else
50       render json: @lecture.errors, status: :unprocessable_entity
51     end
52   end
53
54   # DELETE /lectures/1
55   # DELETE /lectures/1.json
56   def destroy
57     @lecture = Lecture.find(params[:id])
58     @lecture.destroy
59
60     head :no_content
61   end
62
63   def tasks
64     @lecture = Lecture.find(params[:id])
65     render :json => @lecture.tasks
66   end
67 end