Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_video

dev_video
杨树明 5 years ago
commit 616597e67a

@ -19,5 +19,8 @@ module ControllerRescueHandler
rescue_from ActiveRecord::RecordInvalid do |ex|
render_error(ex.record.errors.full_messages.join(','))
end
rescue_from StandardError do |ex|
render_error(ex.message)
end
end
end

@ -2,31 +2,44 @@ class LiveLinksController < ApplicationController
before_action :require_login
before_action :find_course, only: [:index, :create]
before_action :user_course_identity, :teacher_allowed, only: [:create]
before_action :edit_auth, only: [:edit, :update]
def index
lives = @course.live_links.order("id desc")
lives = @course.live_links
order_str = "on_status desc,id desc"
@total_count = lives.size
@my_live_id = @course.live_links.find_by(user_id: current_user.id)&.id
order_str = "#{@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
@course.live_links.create!( create_params.merge(user_id: current_user.id))
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))
render_ok
end
def update
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin?
tip_exception("请勿重复开启") if current_live.on_status && params[:on_status].to_i == 1
ActiveRecord::Base.transaction do
current_live.update!(on_status: params[:on_status])
def edit
@live = current_live
end
# 开启时发送消息,关闭直播时删除对应的消息
if params[:on_status].to_i == 1
LivePublishJob.perform_later(current_live.id)
else
current_live.tidings.destroy_all
def update
if params[:on_status]
tip_exception("请勿重复开启") if current_live.on_status && params[:on_status].to_i == 1
ActiveRecord::Base.transaction do
current_live.update!(on_status: params[:on_status])
# 开启时发送消息,关闭直播时删除对应的消息
if params[:on_status].to_i == 1
LivePublishJob.perform_later(current_live.id)
else
current_live.tidings.destroy_all
end
end
else
current_live.update!(create_params)
end
render_ok
end
@ -40,4 +53,8 @@ class LiveLinksController < ApplicationController
def current_live
@_current_live = LiveLink.find params[:id]
end
def edit_auth
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin?
end
end

@ -6,7 +6,7 @@ class Users::AuthenticationAppliesController < Users::BaseAccountController
Users::ApplyAuthenticationService.call(observed_user, create_params)
render_ok
rescue ApplicationService::Error => ex
render_error(ex.message)
tip_exception(ex.message)
end
def destroy

@ -0,0 +1 @@
json.(@live, :id, :description, :url)

@ -5,5 +5,7 @@ json.lives @lives do |live|
json.author_login live.user.login
json.author_img url_to_avatar(live.user)
json.op_auth live.op_auth?
json.created_at live.created_at.strftime('%Y-%m-%d')
end
json.my_live_id @my_live_id
json.total_count @total_count

@ -550,7 +550,7 @@ Rails.application.routes.draw do
end
end
resources :live_links, only: [:index, :update, :create], shallow: true
resources :live_links, only: [:index, :update, :create, :edit], shallow: true
resources :homework_commons, shallow: true do

Binary file not shown.

Before

Width:  |  Height:  |  Size: 207 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Loading…
Cancel
Save