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.
educoder/app/controllers/weapps/courses_controller.rb

46 lines
1.1 KiB

5 years ago
class Weapps::CoursesController < Weapps::BaseController
# before_action :require_wechat_login!
5 years ago
before_action :teacher_allowed, except: [:create, :show]
5 years ago
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
5 years ago
rescue ApplicationService::Error => ex
render_error(ex.message)
end
def edit
@course = current_course
end
def update
5 years ago
Weapps::UpdateCourseService.call(current_course, update_course_params)
render_ok
end
5 years ago
def show
@course = current_course
@current_user = current_user
end
private
def course_params
params.permit(:name, :course_list_name, :credit, course_module_types: [])
5 years ago
end
5 years ago
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
5 years ago
end