用户课程、搜索课程接口返回数据添加当前用户是否是课程成员、及是否是课程老师两字段
This commit is contained in:
parent
85782cdb8d
commit
e4442bfe04
|
@ -130,10 +130,11 @@ module Mobile
|
|||
desc "搜索课程"
|
||||
params do
|
||||
requires :name, type: String, desc: "课程名"
|
||||
optional :token, type: String
|
||||
end
|
||||
get 'search' do
|
||||
cs = CoursesService.new
|
||||
courses = cs.search_course(params)
|
||||
courses = cs.search_course(params,current_user.nil? ? User.find(2):current_user)
|
||||
present :data, courses, with: Mobile::Entities::Course
|
||||
present :status, 0
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ module Mobile
|
|||
else
|
||||
c = f[:course]
|
||||
end
|
||||
if field == :img_url
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
f[field] if f.is_a?(Hash) && f.key?(field)
|
||||
#f.img_url if f.respond_to?(:img_url)
|
||||
elsif field == :created_at || field == :updated_at
|
||||
|
@ -56,6 +56,8 @@ module Mobile
|
|||
expose :my_homework,using: Mobile::Entities::HomeworkAttach do |f, opt|
|
||||
f[:my_homework] if f.is_a?(Hash) && f.key?(:my_homework)
|
||||
end
|
||||
course_expose :current_user_is_member
|
||||
course_expose :current_user_is_teacher
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,7 +31,7 @@ class CoursesService
|
|||
end
|
||||
|
||||
#搜索课程
|
||||
def search_course params
|
||||
def search_course params,current_user
|
||||
courses_all = Course.all_course
|
||||
name = params[:name]
|
||||
if name.blank?
|
||||
|
@ -44,6 +44,11 @@ class CoursesService
|
|||
@courses_all = @courses;
|
||||
end
|
||||
@courses_all
|
||||
course_list = []
|
||||
@courses_all.each do |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
|
||||
|
||||
#获取头像
|
||||
|
|
|
@ -134,7 +134,7 @@ class UsersService
|
|||
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
|
||||
course_list = []
|
||||
membership.each do |mp|
|
||||
course_list << {:course => mp.course,:img_url => url_to_avatar(mp.course)}
|
||||
course_list << {:course => mp.course,:img_url => url_to_avatar(mp.course),:current_user_is_member => current_user.member_of_course?(mp.course),:current_user_is_teacher => is_course_teacher(current_user,mp.course)}
|
||||
end
|
||||
course_list
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue