From dced5f328ea91506060b077775fa3b5b2e76df3d Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Wed, 20 May 2015 17:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=95=99=E8=A8=80=E5=88=97?= =?UTF-8?q?=E8=A1=A8api=20=E7=BB=99=E7=94=A8=E6=88=B7=E7=95=99=E8=A8=80=20?= =?UTF-8?q?api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 2 +- app/api/mobile/apis/users.rb | 25 +++++++++++++++++++++++++ app/services/users_service.rb | 20 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 008a08f2f..73d1e357c 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -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 diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 147cbfda5..675ad33c5 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -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 diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 071820ba3..41d408dc5 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -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