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.
50 lines
1.2 KiB
50 lines
1.2 KiB
class Weapps::CoursesController < Weapps::BaseController
|
|
before_action :require_login
|
|
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
|
|
|
|
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 current_user.course_identity(current_course) < Course::STUDENT
|
|
end
|
|
end |