|
|
|
@ -7,17 +7,17 @@ class LiveLinksController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
lives = @course.live_links
|
|
|
|
|
order_str = "on_status desc,id desc"
|
|
|
|
|
order_str = "on_status desc, live_time desc"
|
|
|
|
|
@total_count = lives.size
|
|
|
|
|
@my_live_id = @course.live_links.find_by(user_id: current_user.id)&.id
|
|
|
|
|
order_str = "live_links.id = #{@my_live_id} desc, #{order_str}" if @my_live_id.present?
|
|
|
|
|
# order_str = "live_links.id = #{@my_live_id} desc, #{order_str}" if @my_live_id.present?
|
|
|
|
|
lives = lives.order("#{order_str}")
|
|
|
|
|
@lives = paginate lives.includes(user: :user_extension)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
tip_exception("一个老师只能设置一个直播间") if @course.live_links.where(user_id: current_user.id).exists?
|
|
|
|
|
@course.live_links.create!(create_params.merge(user_id: current_user.id))
|
|
|
|
|
on_status = params[:live_time].present? && params[:live_time].to_time <= Time.now ? 1 : 0
|
|
|
|
|
@course.live_links.create!(create_params.merge(user_id: current_user.id, on_status: on_status))
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -38,7 +38,8 @@ class LiveLinksController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
current_live.update!(create_params)
|
|
|
|
|
on_status = params[:live_time].present? && params[:live_time].to_time <= Time.now ? 1 : 0
|
|
|
|
|
current_live.update!(create_params.merge(on_status: on_status))
|
|
|
|
|
end
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
@ -51,7 +52,7 @@ class LiveLinksController < ApplicationController
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def create_params
|
|
|
|
|
params.permit(:url, :description)
|
|
|
|
|
params.permit(:url, :description, :course_name, :platform, :live_time, :duration)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def current_live
|
|
|
|
|