手机API添加回复留言接口

This commit is contained in:
z9hang 2015-02-05 17:32:19 +08:00
parent ef203ff40c
commit 0dfa428377
3 changed files with 57 additions and 1 deletions

View File

@ -22,7 +22,6 @@ 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: '被引用的人'
@ -39,6 +38,25 @@ module Mobile
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

@ -37,4 +37,39 @@ class CommentService
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