You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.0 KiB
70 lines
2.0 KiB
class Weapps::CoursesController < Weapps::BaseController
|
|
before_action :require_login
|
|
before_action :user_course_identity, except: [:create]
|
|
before_action :teacher_allowed, except: [:create, :show, :shixun_homework_category]
|
|
|
|
def create
|
|
return render_error("只有老师身份才能创建课堂") unless current_user.is_teacher?
|
|
course = Course.new(tea_id: current_user.id)
|
|
Weapps::CreateCourseService.call(course, course_params)
|
|
render_ok
|
|
|
|
rescue ApplicationService::Error => ex
|
|
render_error(ex.message)
|
|
end
|
|
|
|
def edit
|
|
@course = current_course
|
|
end
|
|
|
|
def update
|
|
Weapps::UpdateCourseService.call(current_course, update_course_params)
|
|
render_ok
|
|
end
|
|
|
|
def show
|
|
@course = current_course
|
|
@current_user = current_user
|
|
end
|
|
|
|
def shixun_homework_category
|
|
@categories = current_course.shixun_course_modules.first&.course_second_categories
|
|
end
|
|
|
|
# 教师列表
|
|
def teachers
|
|
@course = current_course
|
|
if @course.try(:id) != 1309 || current_user.admin? || current_user.try(:id) == 15582
|
|
@teacher_list = @course.course_members.joins(:user).where("course_members.role in (1, 2, 3)")
|
|
else
|
|
@teacher_list = @course.course_members.joins(:user).where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id}
|
|
and course_members.role = 2))")
|
|
end
|
|
|
|
@teacher_list_size = @teacher_list.size
|
|
|
|
@applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size
|
|
|
|
@teacher_list = @teacher_list.preload(user: [user_extension: :school]).order("CONVERT(CONCAT(users.lastname, users.firstname) USING gbk) COLLATE gbk_chinese_ci asc")
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def course_params
|
|
params.permit(:name, :course_list_name, :credit, course_module_types: [])
|
|
end
|
|
|
|
def update_course_params
|
|
params.permit(:name, :course_list_name, :credit)
|
|
end
|
|
|
|
def current_course
|
|
@_current_course = Course.find params[:id]
|
|
end
|
|
|
|
def teacher_allowed
|
|
return render_forbidden unless @user_course_identity < Course::STUDENT
|
|
end
|
|
end |