-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathrecordings_controller.rb
81 lines (67 loc) · 2.02 KB
/
recordings_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class Api::RecordingsController < ApiController
protect_from_forgery except: %i(create)
before_action :set_recording, only: [:show, :edit, :update, :destroy]
# GET /api/recordings/
def index
@recordings = Recording.recent(100)
end
# GET /api/recordings/1
def show
end
# GET /api/recordings/new
def new
@conference = Recording.new
end
# GET /api/recordings/1/edit
def edit
end
# POST /api/recordings/
def create
event = Event.find_by! guid: params['guid']
@recording = Recording.new(recording_params)
@recording.event = event
respond_to do |format|
if @recording.save
format.json { render :show, status: :created }
else
if @recording.dupe.present?
@recording = @recording.dupe[0]
if @recording.update(recording_params)
format.json { render :show, status: :ok }
else
format.json { render :show, status: :unprocessable_entity }
end
else
Rails.logger.info("JSON: failed to create recording: #{@recording.errors.inspect}")
format.json { render json: @recording.errors.messages, status: :unprocessable_entity }
end
end
end
end
# PATCH/PUT /api/recordings/1
def update
fail ActiveRecord::RecordNotFound unless @recording
respond_to do |format|
if @recording.update(recording_params)
format.json { render :show, status: :ok }
else
format.json { render :show, status: :unprocessable_entity }
end
end
end
# DELETE /api/recordings/1
def destroy
@recording.destroy
respond_to do |format|
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_recording
@recording = Recording.includes([:conference]).find(params[:id])
end
def recording_params
params.require(:recording).permit(:folder, :filename, :mime_type, :language, :translated, :high_quality, :html5, :size, :width, :height, :length, :state)
end
end