用户留言列表api

给用户留言 api
This commit is contained in:
lizanle 2015-05-20 17:27:17 +08:00
parent 2a558c924f
commit dced5f328e
3 changed files with 46 additions and 1 deletions

View File

@ -258,7 +258,7 @@ module Mobile
requires :course_id,type: Integer,desc: '课程id'
optional :name,type:String,desc:'课件名称可能包含的字符'
end
get ":course_id/attachments" do
post ":course_id/attachments" do
cs = CoursesService.new
count = cs.course_attachments params
present :data, count, with: Mobile::Entities::Attachment

View File

@ -94,6 +94,31 @@ module Mobile
present :status, 0
end
desc "用户留言"
params do
requires :token, type: String
requires :user_id, type: Integer,desc: '被留言的用户id'
end
get ':user_id/messages' do
us = UsersService.new
jours = us.get_all_messages params
present :data,jours,with:Mobile::Entities::Jours
present :status,0
end
desc "给用户留言或回复用户留言"
params do
requires :token, type: String
requires :user_id, type: Integer,desc: '被留言的用户id'
requires :content,type:String,desc:'留言内容'
optional :refer_user_id,type:Integer,desc:'被回复的用户id'
end
post ':user_id/leave_message' do
us = UsersService.new
jours = us.leave_messages params,current_user
present :status,0
end
end
end
end

View File

@ -4,6 +4,7 @@ class UsersService
include AvatarHelper
include CoursesHelper
include ApiHelper
include WordsHelper
#将用户注册的功能函数写这里
#参数约定
#成功返回注册后的User实例失败直接抛异常
@ -154,6 +155,25 @@ class UsersService
@user
end
# 获取某个用户的所有留言信息
def get_all_messages params
user = User.find(params[:user_id])
jours = user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
jours.update_all(:is_readed => true, :status => false)
jours.each do |journal|
fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false)
end
jours
end
# 给某个用户留言
def leave_messages params,current_user
user = User.find(params[:user_id])
user.add_jour(current_user, params[:content], params[:refer_user_id] ||= 0)
unless params[:refer_user_id].nil? || params[:refer_user_id] == 0 || params[:refer_user_id] == User.current.id
User.find(params[:refer_user_id]).add_jour(current_user, params[:content], params[:refer_user_id])
end
end