From a7af3f4a6d89e2bd5966ba01e2d6c5661f1e20e6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 14 Nov 2019 20:15:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/weapps/courses_controller.rb | 13 +++++++++++-- app/views/weapps/courses/show.json.jbuilder | 4 ++++ config/routes.rb | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 app/views/weapps/courses/show.json.jbuilder diff --git a/app/controllers/weapps/courses_controller.rb b/app/controllers/weapps/courses_controller.rb index 38f1b99f9..1d510a863 100644 --- a/app/controllers/weapps/courses_controller.rb +++ b/app/controllers/weapps/courses_controller.rb @@ -1,6 +1,6 @@ class Weapps::CoursesController < Weapps::BaseController # before_action :require_wechat_login! - before_action :teacher_allowed, except: [:create] + before_action :teacher_allowed, except: [:create, :show] def create return render_error("只有老师身份才能创建课堂") unless current_user.is_teacher? @@ -17,16 +17,25 @@ class Weapps::CoursesController < Weapps::BaseController end def update - Weapps::UpdateCourseService.call(current_course, course_params) + Weapps::UpdateCourseService.call(current_course, update_course_params) render_ok end + def show + @course = current_course + @current_user = current_user + 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 diff --git a/app/views/weapps/courses/show.json.jbuilder b/app/views/weapps/courses/show.json.jbuilder new file mode 100644 index 000000000..45cd1c040 --- /dev/null +++ b/app/views/weapps/courses/show.json.jbuilder @@ -0,0 +1,4 @@ +json.(@course, :id, :name, :course_members_count, :credit) +json.teachers_count @course.teachers.count +json.students_count @course.students.count +json.course_identity @current_user.course_identity(@course) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6b9c83bc8..d663e7cfb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -880,7 +880,7 @@ Rails.application.routes.draw do post :cancel_sticky, on: :collection end - resources :courses, only: [:create, :update, :edit] + resources :courses, only: [:create, :update, :edit, :show] end resources :users_for_partners, only: [:index]