From 93762e89d37895fb627fcdbd0b932f5ef01a8f2c Mon Sep 17 00:00:00 2001 From: z9han Date: Tue, 23 Dec 2014 11:07:17 +0800 Subject: [PATCH] =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E3=80=81=E9=80=80=E5=87=BA=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AF=BE=E7=A8=8B=EF=BC=8C=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=9A=84=E5=8F=82=E6=95=B0=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 4 ++-- app/controllers/courses_controller.rb | 2 +- app/services/courses_service.rb | 32 ++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 21fec6241..69848a1f4 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -34,7 +34,7 @@ module Mobile post ":id" do authenticate! cs = CoursesService.new - status = cs.join_course({"object_id" => params[:id]},current_user.id) + status = cs.join_course({"object_id" => params[:id]},current_user) out = {status: status} message = case status when 0; "加入成功" @@ -54,7 +54,7 @@ module Mobile delete ":id" do authenticate! cs = CoursesService.new - cs.exit_course({"object_id" => params[:id]}, current_user.id) + cs.exit_course({"object_id" => params[:id]}, current_user) {status: 0} end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 519afb6a8..985c33aab 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -428,7 +428,7 @@ class CoursesController < ApplicationController def create cs = CoursesService.new - @course = cs.create_course params + @course = cs.create_course params,User.current if @course.new_record? respond_to do |format| format.html { render :action => 'new', :layout => 'base' } #Added by young diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 09e4289b5..6e2c84e65 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -49,7 +49,7 @@ class CoursesService url_to_avatar(obj) end - #课程老师或课程学生列表 TODO:更新业务逻辑,当前版本未包含分班功能 + #课程老师或课程学生列表 def course_teacher_or_student_list params,course,current_user if course.is_a?(Course) c = course @@ -110,8 +110,20 @@ class CoursesService end #创建课程 - def create_course params - if User.current.user_extensions.identity + #current_user当前用户对象(不是id) + # params[:course][:name]:课程名称 + #params[:course][:password]:密码 + #params[:course][:description]:描述 + #params[:course][:is_public]:是否公开1公开,0私有 + #params[:course][:open_student]:是否公开学生列表1公开,0不公开,不公开时非课程成员无法看到学生列表 + #params[:course][:course_type]:暂时默认给1值。 + #params[:term]:学期(秋季学期或春季学期) + #params[:time]: 年份(例:2014) + #params[:setup_time]:暂不传(貌似已经没用了) + #params[:endup_time]: 暂不传(貌似已经没用了) + #params[:class_period]:学时总数 + def create_course params,current_user + if current_user.user_extensions.identity @course = Course.new @course.extra = 'course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s @course.safe_attributes = params[:course] @@ -145,6 +157,7 @@ class CoursesService end #验证编辑课程的权限 + #当前 def edit_course_authorize(current_user,course) unless current_user.allowed_to?({:controller => 'courses', :action => 'update'}, course) raise '403' @@ -152,6 +165,15 @@ class CoursesService end #编辑课程 需验证权限 + # params[:course][:name]:课程名称 + #params[:course][:password]:密码 + #params[:course][:description]:描述 + #params[:course][:is_public]:是否公开1公开,0私有 + #params[:course][:open_student]:是否公开学生列表1公开,0不公开,不公开时非课程成员无法看到学生列表 + #params[:course][:course_type]:暂时默认给1值。 + #params[:term]:学期(秋季学期或春季学期) + #params[:time]: 年份(例:2014) + #params[:class_period]:学时总数 def edit_course params,course course.safe_attributes = params[:course] course.time = params[:time] @@ -171,6 +193,8 @@ class CoursesService end #退出课程 + #object_id: 课程id + #user:当前用户 def exit_course params,user @member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id) @member.first.destroy @@ -182,6 +206,8 @@ class CoursesService end #加入课程 + #object_id:课程id + #course_password :加入课程的密码 #@state == 0 加入成功 #@state == 1 密码错误 #@state == 2 课程已过期 请联系课程管理员重启课程。(在配置课程处)