socialforge/app/api/mobile/apis/watches.rb

50 lines
1.3 KiB
Ruby
Raw Normal View History

2014-12-10 18:26:38 +08:00
#coding=utf-8
2014-12-10 16:23:56 +08:00
module Mobile
module Apis
class Watches < Grape::API
resource :watches do
desc "获取所有关注"
params do
requires :token, type: String
end
get do
authenticate!
2014-12-10 17:29:39 +08:00
us = UsersService.new
ws = us.user_watcher(id: current_user.id)
2014-12-15 20:17:35 +08:00
present :data, ws, with: Mobile::Entities::User
present :status, 0
2014-12-10 16:23:56 +08:00
end
desc "关注某人"
params do
requires :token, type: String
requires :object_id, type: Integer, desc: '关注的用户的id'
end
post do
authenticate!
ws = WatchesService.new
2014-12-18 13:37:23 +08:00
o = ws.watch(params.merge({current_user_id:current_user.id, object_type:'user' }) )
present :data, o, with: Mobile::Entities::User
present :status, 0
2014-12-10 16:23:56 +08:00
end
desc "取消关注"
params do
requires :token, type: String
requires :object_id, type: Integer, desc: '取消关注的用户的id'
end
delete do
authenticate!
ws = WatchesService.new
2014-12-10 17:29:39 +08:00
ws.unwatch(params.merge({current_user_id:current_user.id, object_type:'user' }) )
{status: 0}
2014-12-10 16:23:56 +08:00
end
end
end
end
2014-12-15 20:17:35 +08:00
end