获取所有课程及显示课程接口返回数据中添加当前用户是否是课程成员、及是否是课程教师字段
This commit is contained in:
parent
e4442bfe04
commit
a6882d0f88
|
@ -8,10 +8,11 @@ module Mobile
|
|||
optional :school_id, type: Integer, desc: '传入学校id,返回该学校课程列表'
|
||||
requires :per_page_count, type: Integer, desc: '每页总数'
|
||||
requires :page, type: Integer, desc: '当前页码'
|
||||
optional :token, type: String
|
||||
end
|
||||
get do
|
||||
cs = CoursesService.new
|
||||
courses = cs.course_list(params)
|
||||
courses = cs.course_list(params,current_user.nil? ? User.find(2):current_user)
|
||||
present :data, courses, with: Mobile::Entities::Course
|
||||
present :status, 0
|
||||
end
|
||||
|
@ -166,13 +167,15 @@ module Mobile
|
|||
desc "返回单个课程"
|
||||
params do
|
||||
requires :id, type: Integer
|
||||
optional :token, type: String
|
||||
end
|
||||
route_param :id do
|
||||
get do
|
||||
cs = CoursesService.new
|
||||
course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user))
|
||||
#course = Course.find(params[:id])
|
||||
{status: 0, data: course}
|
||||
present :data, course, with: Mobile::Entities::Course
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class CoursesService
|
|||
#参数school_id为0或不传时返回所有课程,否则返回对应学校的课程
|
||||
#参数per_page_count分页功能,每页显示的课程数
|
||||
#参数page分页功能,当前页码
|
||||
def course_list params
|
||||
def course_list params,current_user
|
||||
@school_id = params[:school_id]
|
||||
per_page_option = params[:per_page_count] || 10
|
||||
page_no = params[:page] || 1
|
||||
|
@ -25,7 +25,7 @@ class CoursesService
|
|||
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
||||
course_list = []
|
||||
@courses.each do |course|
|
||||
course_list << {:course => course,:img_url => url_to_avatar(course)}
|
||||
course_list << {:course => course,:img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course)}
|
||||
end
|
||||
course_list
|
||||
end
|
||||
|
@ -163,7 +163,7 @@ class CoursesService
|
|||
unless (course.is_public == 1 || currnet_user.member_of_course?(@course)|| currnet_user.admin?)
|
||||
raise '403'
|
||||
end
|
||||
course
|
||||
{:course => course,:img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course)}
|
||||
end
|
||||
|
||||
#创建课程
|
||||
|
|
Loading…
Reference in New Issue