parent
c05a87ca37
commit
759e68621f
|
@ -3,6 +3,9 @@ module Mobile
|
||||||
module Apis
|
module Apis
|
||||||
class Courses < Grape::API
|
class Courses < Grape::API
|
||||||
resource :courses do
|
resource :courses do
|
||||||
|
def self.get_service
|
||||||
|
CoursesService.new
|
||||||
|
end
|
||||||
desc "获取所有课程"
|
desc "获取所有课程"
|
||||||
params do
|
params do
|
||||||
optional :school_id, type: Integer, desc: '传入学校id,返回该学校课程列表'
|
optional :school_id, type: Integer, desc: '传入学校id,返回该学校课程列表'
|
||||||
|
@ -338,8 +341,55 @@ module Mobile
|
||||||
cs = CoursesService.new
|
cs = CoursesService.new
|
||||||
student_works = cs.student_work_list params,current_user
|
student_works = cs.student_work_list params,current_user
|
||||||
present :data,student_works.all,with:Mobile::Entities::StudentWork
|
present :data,student_works.all,with:Mobile::Entities::StudentWork
|
||||||
|
present :status,0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc '讨论区信息'
|
||||||
|
params do
|
||||||
|
requires :token,type:String
|
||||||
|
requires :course_id,type:Integer,desc:'课程id'
|
||||||
|
optional :page,type:Integer,desc:'页码'
|
||||||
|
end
|
||||||
|
get ':course_id/board_message_list' do
|
||||||
|
cs = CoursesService.new
|
||||||
|
board_messages_list = cs.board_message_list params,current_user
|
||||||
|
present :data,board_messages_list.all,with:Mobile::Entities::Message
|
||||||
|
present :status,0
|
||||||
|
end
|
||||||
|
|
||||||
|
desc '讨论区某主题的回复列表'
|
||||||
|
params do
|
||||||
|
requires :token,type:String
|
||||||
|
requires :board_id,type:Integer,desc:'讨论区id'
|
||||||
|
requires :msg_id,type:Integer,desc:'讨论主题id'
|
||||||
|
optional :page,type:Integer,desc:'页码'
|
||||||
|
end
|
||||||
|
get ':board_id/board_message_reply_list' do
|
||||||
|
cs = Courses.get_service
|
||||||
|
board_messages_list = cs.board_message_reply_list params,current_user
|
||||||
|
present :data,board_messages_list.all,with:Mobile::Entities::Message
|
||||||
|
present :status,0
|
||||||
|
end
|
||||||
|
|
||||||
|
desc '讨论区回复'
|
||||||
|
params do
|
||||||
|
requires :token,type:String
|
||||||
|
requires :board_id,type:Integer,desc:'讨论区id'
|
||||||
|
requires :parent_id,type:Integer,desc:'本回复父id'
|
||||||
|
requires :subject,type:String,desc:'本回复主题'
|
||||||
|
requires :content,type:String,desc:'本回复内容'
|
||||||
|
requires :root_id,type:Integer,desc:'本回复根id'
|
||||||
|
requires :quote,type:String,desc:'本回复引用内容'
|
||||||
|
end
|
||||||
|
post ':board_id/board_message_reply' do
|
||||||
|
cs = Courses.get_service
|
||||||
|
board_messages = cs.board_message_reply params,current_user
|
||||||
|
present :data,board_messages,with:Mobile::Entities::Message
|
||||||
|
present :status,0
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -654,9 +654,9 @@ class CoursesService
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if current_user == @user || current_user.admin?
|
if current_user == @user || current_user.admin?
|
||||||
membership = @user.coursememberships.page(1).per(15)
|
membership = @user.coursememberships.page(1).per(5)
|
||||||
else
|
else
|
||||||
membership = @user.coursememberships.page(1).per(15).all(:conditions => Course.visible_condition(current_user))
|
membership = @user.coursememberships.page(1).per(5).all(:conditions => Course.visible_condition(current_user))
|
||||||
end
|
end
|
||||||
if membership.nil? || membership.count == 0
|
if membership.nil? || membership.count == 0
|
||||||
raise l(:label_no_courses, :locale => get_user_language(current_user))
|
raise l(:label_no_courses, :locale => get_user_language(current_user))
|
||||||
|
@ -678,12 +678,11 @@ class CoursesService
|
||||||
end
|
end
|
||||||
|
|
||||||
# 课程讨论区
|
# 课程讨论区
|
||||||
# latest_message = course.boards.first.topics.page(1).per(2)
|
latest_message = course.boards.first.topics.page(1).per(2)
|
||||||
# unless latest_message.first.nil?
|
unless latest_message.first.nil?
|
||||||
# latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count,
|
latest_course_dynamics << {:type => 2, :time => latest_message.first.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count,
|
||||||
# :topics => latest_message.all}
|
:topics => latest_message.all}
|
||||||
# dynamics_count += 1
|
end
|
||||||
# end
|
|
||||||
|
|
||||||
# 课程资源
|
# 课程资源
|
||||||
# latest_attachment = course.attachments.order("created_on desc").page(1).per(2)
|
# latest_attachment = course.attachments.order("created_on desc").page(1).per(2)
|
||||||
|
@ -788,6 +787,45 @@ class CoursesService
|
||||||
student_works
|
student_works
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 获取课程的讨论区信息
|
||||||
|
def board_message_list params,current_user
|
||||||
|
# 课程讨论区
|
||||||
|
course = Course.find(params[:course_id])
|
||||||
|
latest_message = course.boards.first.topics.page(params[:page] || 1).per(10)
|
||||||
|
end
|
||||||
|
|
||||||
|
#获取回复列表
|
||||||
|
def board_message_reply_list params,current_user
|
||||||
|
board = Board.find(params[:board_id])
|
||||||
|
reply_list = board.topics.where("id = #{params[:msg_id]}").first.children.order("created_on desc").page(params[:page] || 1).per(10)
|
||||||
|
end
|
||||||
|
|
||||||
|
#回复讨论区
|
||||||
|
def board_message_reply params,current_user
|
||||||
|
author = Message.find(params[:parent_id]).author
|
||||||
|
quote = "<blockquote>" << author.realname << "(" << author.nickname << ")写到: <br/>" << params[:quote] <<"<div class='cl'></div></blockquote>"
|
||||||
|
reply = Message.new
|
||||||
|
reply.author = current_user
|
||||||
|
reply.board = Board.find(params[:board_id])
|
||||||
|
params[:reply] = {}
|
||||||
|
params[:reply][:subject] = params[:subject] #本回复标题
|
||||||
|
params[:reply][:content] = params[:content] #本回复内容
|
||||||
|
params[:reply][:quote] = {}
|
||||||
|
params[:reply][:quote][:quote] = params[:quote] #本回复引用的内容,也是父id内容
|
||||||
|
params[:reply][:parent_topic] = params[:parent_id] # 父id
|
||||||
|
params[:reply][:board_id] = params[:board_id] #讨论区id
|
||||||
|
params[:reply][:id] = params[:root_id] #根id
|
||||||
|
reply.safe_attributes = params[:reply]
|
||||||
|
if params[:root_id] == params[:parent_id]
|
||||||
|
reply.content = reply.content
|
||||||
|
else
|
||||||
|
reply.content = quote + reply.content
|
||||||
|
end
|
||||||
|
|
||||||
|
Message.find(params[:root_id]).children << reply
|
||||||
|
reply
|
||||||
|
end
|
||||||
|
|
||||||
# # 开启匿评
|
# # 开启匿评
|
||||||
# #statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限
|
# #statue 1:启动成功,2:启动失败,作业总数大于等于2份时才能启动匿评,3:已开启匿评,请务重复开启,4:没有开启匿评的权限
|
||||||
# def start_anonymous_comment params,current_user
|
# def start_anonymous_comment params,current_user
|
||||||
|
|
Loading…
Reference in New Issue