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

dev_video
caicai8 5 years ago
commit 9a92e57ee1

@ -6,12 +6,17 @@ module ControllerRescueHandler
Util.logger_error e
render json: {status: -1, message: "接口异常"}
end
rescue_from Mysql2::Error do |e|
Util.logger_error e
render json: {status: -1, message: "接口数据异常"}
end
# rescue_from ActionView::MissingTemplate, with: :object_not_found
# rescue_from ActiveRecord::RecordNotFound, with: :object_not_found
rescue_from Educoder::TipException, with: :tip_show
rescue_from ::ActionView::MissingTemplate, with: :missing_template
rescue_from ActiveRecord::RecordNotFound, with: :object_not_found
rescue_from ActionController::ParameterMissing, with: :render_parameter_missing
# form validation error
rescue_from ActiveModel::ValidationError do |ex|
render_error(ex.model.errors.full_messages.join(','))
@ -19,5 +24,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

@ -1,37 +1,52 @@
class LiveLinksController < ApplicationController
before_action :require_login
before_action :find_course, only: [:index, :create]
before_action :user_course_identity
before_action :teacher_allowed, only: [:create]
before_action :user_course_identity, :teacher_allowed, only: [:create]
before_action :edit_auth, only: [:edit, :update, :destroy]
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 = "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
@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 edit
@live = current_live
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
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])
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
# 开启时发送消息,关闭直播时删除对应的消息
if params[:on_status].to_i == 1
LivePublishJob.perform_later(current_live.id)
end
end
else
current_live.update!(create_params)
end
render_ok
end
def destroy
current_live.destroy!
render_ok
end
private
def create_params
@ -41,4 +56,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

@ -19,8 +19,9 @@ class TidingsController < ApplicationController
end
tidings = tidings.where(tiding_type: tiding_types) if tiding_types.present?
tidings = tidings.where(container_type: 'JoinCourse') if params[:type] == 'course_apply'
@course_apply_count = tidings.where("created_at > '#{@onclick_time}'").where(container_type: 'JoinCourse').count
tidings = tidings.where(container_type: 'JoinCourse', status: 0) if params[:type] == 'course_apply'
# @course_apply_count = tidings.where("created_at > '#{@onclick_time}'").where(container_type: 'JoinCourse', status: 0).count
@course_apply_count = tidings.where("created_at > '#{@onclick_time}'").where(container_type: 'JoinCourse', status: 0).count
tidings = tidings.where(container_type: 'ProjectPackage') if params[:type] == 'project_package'

@ -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

@ -111,6 +111,7 @@ class StudentWork < ApplicationRecord
# 作品总体评价
def overall_appraisal
return "--" if work_status == 0
case (self.work_score.to_f / homework_common.total_score).round(2)
when (0.90..1.00)
'优秀'

@ -36,10 +36,10 @@ class Admins::ImportCourseMemberService < ApplicationService
member = course.course_members.find_by(user_id: user.id, role: data.role.to_i)
# 如果已是课堂成员且是学生身份and不在指定的分班则移动到该分班
if member.present? && member.role == 'STUDENT' && course_group && member.course_group_id != course_group&.id
member.update!(course_group_id: course_group&.id)
if member.present? && member.role == 'STUDENT' && course_group && member.course_group_id != course_group&.id.to_i
member.update!(course_group_id: course_group&.id.to_i)
elsif member.blank?
course.course_members.create!(user_id: user.id, role: data.role.to_i, course_group_id: course_group&.id)
course.course_members.create!(user_id: user.id, role: data.role.to_i, course_group_id: course_group&.id.to_i)
extra =
case data.role.to_i
when 2 then 9

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

@ -1,8 +1,11 @@
json.lives @lives do |live|
json.(live, :id, :url, :description, :on_status)
json.(live, :id, :description, :on_status)
json.url live.on_status ? live.url : ""
json.author_name live.user.show_real_name
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

@ -4,6 +4,7 @@ json.course_name @course.name
json.work_id @work.id
json.work_efficiency @homework.work_efficiency
json.has_commit @work.myshixun.present?
json.work_status @work.work_status
if @shixun
json.shixun_name @shixun.name
# 总体评价

@ -170,7 +170,7 @@ zh-CN:
name: '名称'
tag_discipline:
name: '名称'
live:
live_link:
description: '说明'
url: '链接'

@ -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, :destroy], shallow: true
resources :homework_commons, shallow: true do

@ -0,0 +1,7 @@
class MigrateDefalutToTiding < ActiveRecord::Migration[5.2]
def change
change_column_default :tidings, :status, from: nil, to: 0
Tiding.where(status: nil).update_all(status: 0)
end
end

@ -0,0 +1,9 @@
class MigrateTidingStatus < ActiveRecord::Migration[5.2]
def change
Tiding.where(container_type: "JoinCourse", status: 0).each do |tiding|
unless CourseMessage.where(course_message_id: tiding.trigger_user_id, course_id: tiding.container_id, course_message_type: "JoinCourseRequest", status: 0).exists?
tiding.update!(status: 1)
end
end
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 207 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Loading…
Cancel
Save