2015-10-06 15:21:46 +03:00
|
|
|
class TalkPreferencesController < ApplicationController
|
|
|
|
def index
|
2015-10-08 02:58:34 +03:00
|
|
|
@talks = Talk.find(:all, from: :halfnarp_friendly, params: {locale: I18n.locale}).to_a.shuffle(random: Random.new(sort_seed))
|
2015-10-06 15:21:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@talk_preference = TalkPreference.find_by hashed_unique_id: params[:id]
|
|
|
|
render json: {talk_ids: @talk_preference.talks}
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@talk_preference = TalkPreference.new talk_preference_params
|
2015-10-06 16:05:15 +03:00
|
|
|
@talk_preference.ip_address = current_ip_address
|
2015-10-06 15:21:46 +03:00
|
|
|
|
|
|
|
if @talk_preference.save
|
|
|
|
render json: {
|
|
|
|
update_url: talk_preference_url(@talk_preference),
|
|
|
|
hashed_uid: @talk_preference.hashed_unique_id,
|
|
|
|
uid: @talk_preference.id
|
|
|
|
}, status: :created
|
|
|
|
else
|
|
|
|
render status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@talk_preference = TalkPreference.find params[:id]
|
|
|
|
|
2016-10-05 17:56:24 +03:00
|
|
|
@talk_preference.transaction do
|
|
|
|
@talk_preference.selected_talks.destroy_all
|
|
|
|
|
2017-09-28 15:37:31 +03:00
|
|
|
if params[:talk_preference].blank? || @talk_preference.update(talk_preference_params)
|
2016-10-05 17:56:24 +03:00
|
|
|
render json: {
|
2017-09-28 15:37:31 +03:00
|
|
|
update_url: talk_preference_url(@talk_preference),
|
|
|
|
hashed_uid: @talk_preference.hashed_unique_id,
|
|
|
|
uid: @talk_preference.id
|
|
|
|
}
|
2016-10-05 17:56:24 +03:00
|
|
|
else
|
|
|
|
head :unprocessable_entity
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
2015-10-06 15:21:46 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def talk_preference_params
|
2016-10-05 17:56:24 +03:00
|
|
|
params.require(:talk_preference).permit(selected_talks_attributes: [:talk_id])
|
2015-10-06 15:21:46 +03:00
|
|
|
end
|
|
|
|
end
|