2014-12-10 18:26:38 +08:00
|
|
|
|
#coding=utf-8
|
2014-11-27 19:43:04 +08:00
|
|
|
|
module Mobile
|
2014-12-09 15:16:47 +08:00
|
|
|
|
module Apis
|
2014-12-09 16:36:43 +08:00
|
|
|
|
class Users < Grape::API
|
|
|
|
|
resource :users do
|
2014-12-04 10:11:55 +08:00
|
|
|
|
|
2014-12-10 16:23:56 +08:00
|
|
|
|
desc "注册用户"
|
2014-12-09 16:36:43 +08:00
|
|
|
|
params do
|
|
|
|
|
requires :login, type: String, desc: 'username'
|
|
|
|
|
requires :mail, type: String, desc: 'mail'
|
|
|
|
|
requires :password, type: String, desc: 'password'
|
|
|
|
|
end
|
|
|
|
|
post do
|
|
|
|
|
us = UsersService.new
|
2014-12-10 17:29:39 +08:00
|
|
|
|
user = us.register params.merge(:password_confirmation => params[:password],
|
|
|
|
|
:should_confirmation_password => true)
|
2015-04-10 14:33:03 +08:00
|
|
|
|
raise "该邮箱已经被注册过了" if user.new_record?
|
2014-12-15 14:06:00 +08:00
|
|
|
|
|
2014-12-10 17:29:39 +08:00
|
|
|
|
present :data, user, with: Mobile::Entities::User
|
|
|
|
|
present :status, 0
|
2014-11-27 19:43:04 +08:00
|
|
|
|
end
|
2014-12-09 15:16:47 +08:00
|
|
|
|
|
2015-01-06 16:59:22 +08:00
|
|
|
|
desc "显示用户"
|
|
|
|
|
params do
|
2015-02-06 14:29:42 +08:00
|
|
|
|
requires :id, type: Integer
|
2015-01-06 16:59:22 +08:00
|
|
|
|
end
|
2015-02-06 14:29:42 +08:00
|
|
|
|
route_param :id do
|
|
|
|
|
get do
|
|
|
|
|
us = UsersService.new
|
|
|
|
|
ue = us.show_user params
|
|
|
|
|
present :data, ue,with: Mobile::Entities::User
|
|
|
|
|
present :status, 0
|
|
|
|
|
end
|
2015-01-06 16:59:22 +08:00
|
|
|
|
end
|
2014-12-10 11:56:33 +08:00
|
|
|
|
|
2014-12-10 16:23:56 +08:00
|
|
|
|
desc "修改用户"
|
2014-12-10 11:56:33 +08:00
|
|
|
|
params do
|
2014-12-10 16:23:56 +08:00
|
|
|
|
requires :token, type: String
|
2014-12-10 11:56:33 +08:00
|
|
|
|
#optional :file, type: File, desc: 'avatar'
|
|
|
|
|
optional :occupation, type: String
|
|
|
|
|
optional :brief_introduction, type: String
|
|
|
|
|
optional :province, type: String
|
|
|
|
|
optional :city, type: String
|
|
|
|
|
optional :gender, type: Integer
|
|
|
|
|
end
|
|
|
|
|
put ':id' do
|
|
|
|
|
authenticate!
|
|
|
|
|
us = UsersService.new
|
2014-12-10 17:29:39 +08:00
|
|
|
|
ue = us.edit_user params.merge(id: current_user.id)
|
2015-01-06 16:51:44 +08:00
|
|
|
|
present :data, ue,with: Mobile::Entities::User
|
2014-12-10 17:29:39 +08:00
|
|
|
|
present :status, 0
|
2014-12-10 16:51:19 +08:00
|
|
|
|
end
|
|
|
|
|
|
2015-01-06 17:46:16 +08:00
|
|
|
|
desc '获取用户课程'
|
|
|
|
|
params do
|
2015-01-21 11:28:09 +08:00
|
|
|
|
optional :token, type: String
|
2015-01-06 17:46:16 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
get ':id/courses' do
|
|
|
|
|
us = UsersService.new
|
|
|
|
|
ue = us.user_courses_list params,current_user.nil? ? User.find(2):current_user
|
|
|
|
|
present :data, ue,with: Mobile::Entities::Course
|
|
|
|
|
present :status, 0
|
|
|
|
|
end
|
|
|
|
|
|
2014-12-10 16:51:19 +08:00
|
|
|
|
|
|
|
|
|
desc '修改密码'
|
|
|
|
|
params do
|
|
|
|
|
requires :token, type: String
|
|
|
|
|
requires :password, type:String , desc: '原密码'
|
|
|
|
|
requires :new_password, type: String, desc: '新密码'
|
|
|
|
|
end
|
|
|
|
|
post 'password' do
|
|
|
|
|
authenticate!
|
|
|
|
|
us = UsersService.new
|
2014-12-23 14:46:23 +08:00
|
|
|
|
user = us.change_password params.merge(current_user_id: current_user.id,
|
2014-12-23 10:16:23 +08:00
|
|
|
|
new_password_confirmation: params[:new_password])
|
2014-12-10 17:29:39 +08:00
|
|
|
|
present :data, user, with: Mobile::Entities::User
|
|
|
|
|
present :status, 0
|
2014-12-10 11:56:33 +08:00
|
|
|
|
end
|
|
|
|
|
|
2015-02-06 14:29:42 +08:00
|
|
|
|
desc "用户搜索"
|
2014-12-13 21:52:26 +08:00
|
|
|
|
params do
|
|
|
|
|
requires :name, type: String, desc: '用户名关键字'
|
2016-01-22 17:27:21 +08:00
|
|
|
|
requires :search_by, type: String,desc: '搜索依据:0 登录名,1 用户名,2 邮箱,3 登录名和姓名'
|
2015-05-13 09:56:34 +08:00
|
|
|
|
optional :is_search_assitant,type:Integer,desc:'是否搜索注册用户来作为助教'
|
2015-05-15 09:06:36 +08:00
|
|
|
|
optional :course_id,type:Integer,desc: '课程id,搜索注册用户不为该课程教师的其他用户'
|
2015-05-15 14:04:05 +08:00
|
|
|
|
optional :user_id,type:Integer,desc:'用户id'
|
2014-12-13 21:52:26 +08:00
|
|
|
|
end
|
2015-02-06 14:29:42 +08:00
|
|
|
|
get 'search/search_user' do
|
2014-12-13 21:52:26 +08:00
|
|
|
|
us = UsersService.new
|
|
|
|
|
user = us.search_user params
|
|
|
|
|
present :data, user, with: Mobile::Entities::User
|
|
|
|
|
present :status, 0
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-20 17:27:17 +08:00
|
|
|
|
desc "用户留言"
|
|
|
|
|
params do
|
|
|
|
|
requires :token, type: String
|
|
|
|
|
requires :user_id, type: Integer,desc: '被留言的用户id'
|
2015-05-23 17:13:38 +08:00
|
|
|
|
requires :page,type:Integer,desc:'请求数据的页码'
|
2015-05-20 17:27:17 +08:00
|
|
|
|
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
|
|
|
|
|
|
2015-05-26 09:48:22 +08:00
|
|
|
|
desc "回复用户留言"
|
2015-05-20 17:27:17 +08:00
|
|
|
|
params do
|
|
|
|
|
requires :token, type: String
|
|
|
|
|
requires :user_id, type: Integer,desc: '被留言的用户id'
|
|
|
|
|
requires :content,type:String,desc:'留言内容'
|
2015-05-21 15:57:35 +08:00
|
|
|
|
requires :ref_user_id,type:Integer,desc:'被回复的用户id'
|
|
|
|
|
requires :parent_id,type:Integer,desc:'留言父id'
|
|
|
|
|
requires :ref_message_id,type:Integer,desc:'引用消息id'
|
2015-05-28 17:51:50 +08:00
|
|
|
|
optional :type,type:Integer,desc:'回复类型'
|
|
|
|
|
optional :course_id,type:Integer,desc:'课程id'
|
2015-05-20 17:27:17 +08:00
|
|
|
|
end
|
2015-05-26 09:48:22 +08:00
|
|
|
|
post ':user_id/reply_message' do
|
2015-05-20 17:27:17 +08:00
|
|
|
|
us = UsersService.new
|
2015-05-21 15:57:35 +08:00
|
|
|
|
jours = us.reply_user_messages params,current_user
|
2015-05-20 17:27:17 +08:00
|
|
|
|
present :status,0
|
|
|
|
|
end
|
|
|
|
|
|
2015-05-26 09:48:22 +08:00
|
|
|
|
desc "给用户留言"
|
|
|
|
|
params do
|
|
|
|
|
requires :token, type: String
|
|
|
|
|
requires :user_id, type: Integer,desc:'被留言的用户id'
|
|
|
|
|
requires :content, type: String,desc:'留言内容'
|
|
|
|
|
end
|
|
|
|
|
post ':user_id/leave_message' do
|
|
|
|
|
us = UsersService.new
|
|
|
|
|
us.leave_message params,current_user
|
|
|
|
|
present :data,0
|
|
|
|
|
end
|
2015-05-28 17:51:50 +08:00
|
|
|
|
|
|
|
|
|
desc "与我相关"
|
|
|
|
|
params do
|
|
|
|
|
requires :token, type: String
|
|
|
|
|
requires :page,type:Integer,desc:'页码'
|
|
|
|
|
end
|
|
|
|
|
get ':user_id/all_my_dynamic' do
|
|
|
|
|
us = UsersService.new
|
|
|
|
|
my_jours = us.reply_my_messages params,current_user
|
|
|
|
|
present :data,my_jours,with:Mobile::Entities::Jours
|
|
|
|
|
present :status,0
|
|
|
|
|
end
|
2014-12-09 15:16:47 +08:00
|
|
|
|
end
|
2014-11-27 19:43:04 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|