This commit is contained in:
sw 2015-02-06 09:32:50 +08:00
commit 50244e6860
4 changed files with 67 additions and 7 deletions

View File

@ -22,22 +22,41 @@ module Mobile
desc '作业留言(教师布置的作业)'
params do
requires :token, type: String
requires :id, type: Integer,desc: '老师布置的作业id'
requires :message,type: String, desc: '留言'
optional :reference_content, type: String ,desc: '引用的内容'
optional :reference_user_id, type: Integer,desc: '被引用的人'
#optional :reference_content, type: String ,desc: '引用的内容'
#optional :reference_user_id, type: Integer,desc: '被引用的人'
end
post 'create_homework_message' do
post ':id/create_homework_message' do
cs_params = {
id: params[:id],
token: params[:token],
reference_content: params[:reference_content],
bid_message: params.reject{|k,v| [:id,:token,:reference_content].include?(k)}}
cs = CommentService.new
cs.homework_message cs_params,current_user
message = cs.homework_message cs_params,current_user
present :data, message, with: Mobile::Entities::Jours
present :status, 0
end
desc '回复留言'
params do
requires :token, type: String
requires :reference_id, type: Integer,desc: '所属留言树的根留言id最顶层的非回复的留言,留言对象中的m_parent_id'
requires :reference_user_id,type: Integer ,desc: '被回复的留言的作者id'
#requires :reference_message_id,type: Integer,desc: '被回复的留言的id'
requires :user_notes,type: String,desc: '留言的内容'
requires :jour_type,type: String,desc: '等于父留言的jour_type'
requires :jour_id,type:Integer, desc: '等于父留言的jour_id'
end
post ':reference_message_id/create_reply'do
cs = CommentService.new
message = cs.create_reply params,current_user
raise "create reply failed #{message.errors.full_messages}" if message.new_record?
present :data, message, with: Mobile::Entities::Jours
present :status, 0
end
end
end
end

View File

@ -18,12 +18,15 @@ module Mobile
end
end
jours_expose :id
jours_expose :jour_type
jours_expose :jour_id
expose :user,using: Mobile::Entities::User do |f, opt|
f.user
end
jours_expose :created_on
jours_expose :notes
jours_expose :m_reply_id
jours_expose :m_parent_id
expose :reply_user,using: Mobile::Entities::User do |f, opt|
f.at_user
end

View File

@ -93,7 +93,9 @@ class Bid < ActiveRecord::Base
# 'deadline'
def add_jour(user, notes, reference_user_id = 0, options = {})
if options.count == 0
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id)
jfm = JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id)
self.journals_for_messages << jfm
jfm
else
jfm = self.journals_for_messages.build(options)
jfm.save

View File

@ -28,12 +28,48 @@ class CommentService
@m = message
end
refer_user_id = params[:bid_message][:reference_user_id].to_i
@bid.add_jour(current_user, message, refer_user_id)
jfm = @bid.add_jour(current_user, message, refer_user_id)
end
#@user = @bid.author
#@jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
#@jour = paginateHelper @jours,10
@bid.set_commit(@feedback_count)
jfm
end
#回复留言接口
def create_reply params,current_user
# 这里是创建回复所使用的方法,此方法只针对回复,每一个新的留言并不在此方法管理范围内。
# 由于多个地方用到了留言而之前的表设计也有jour_type/jour_id这类信息
# 所以在方法 add_reply_adapter 中判断所有调用此方法的来源页面,
# 为了保证兼容以往所有的代码,保证以往的方法可以调用,在返回页面中都做了各式各样的判断。
# 页面保证 render new_respond/journal_reply
# 修改 add_reply_adapter 中可以确保留言创建成功
# 删除留言功能要调用destroy也记得在destroy.js中修改
# deny api. api useless
parent_id = params[:reference_id]
author_id = current_user.id
reply_user_id = params[:reference_user_id]
reply_id = params[:reference_message_id] # 暂时不实现
content = params[:user_notes]
jour_type = params[:jour_type]
jour_id = params[:jour_id]
@show_name = params[:show_name] == "true"
options = {
:jour_id => jour_id,
:jour_type => jour_type,
:user_id => author_id,
:status => true,
:m_parent_id => parent_id,
:m_reply_id => reply_id,
:reply_id => reply_user_id,
:notes => content,
:is_readed => false}
@jfm = ::JournalsForMessage.new(options)
#@save_succ = true if @jfm.errors.empty?
@jfm.save
@jfm
end
end