Merge branch 'api' of http://repository.trustie.net/xianbo/trustie2 into api
commit
7d70a6b2cb
@ -0,0 +1,53 @@
|
|||||||
|
module Mobile
|
||||||
|
module Apis
|
||||||
|
class Watches < Grape::API
|
||||||
|
resource :watches do
|
||||||
|
|
||||||
|
desc "获取所有关注"
|
||||||
|
params do
|
||||||
|
requires :token, type: String
|
||||||
|
end
|
||||||
|
get do
|
||||||
|
authenticate!
|
||||||
|
ws = UsersService.new
|
||||||
|
ws.user_watcher(id: current_user.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
desc "关注某人"
|
||||||
|
params do
|
||||||
|
requires :token, type: String
|
||||||
|
requires :object_id, type: Integer, desc: '关注的用户的id'
|
||||||
|
end
|
||||||
|
post do
|
||||||
|
authenticate!
|
||||||
|
ws = WatchesService.new
|
||||||
|
begin
|
||||||
|
o = ws.watch(params.merge({current_user_id:current_user.id, object_type:'user' }) )
|
||||||
|
{status:0 , data: o}
|
||||||
|
rescue =>e
|
||||||
|
{status:1, message: e.message}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
desc "取消关注"
|
||||||
|
params do
|
||||||
|
requires :token, type: String
|
||||||
|
requires :object_id, type: Integer, desc: '取消关注的用户的id'
|
||||||
|
end
|
||||||
|
delete do
|
||||||
|
authenticate!
|
||||||
|
ws = WatchesService.new
|
||||||
|
begin
|
||||||
|
ws.unwatch(params.merge({current_user_id:current_user.id, object_type:'user' }) )
|
||||||
|
{status:0}
|
||||||
|
rescue =>e
|
||||||
|
{status:1, message: e.message}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,4 +1,4 @@
|
|||||||
class Service
|
class WatchesService
|
||||||
def watch params
|
def watch params
|
||||||
@current_user = User.find(params[:current_user_id])
|
@current_user = User.find(params[:current_user_id])
|
||||||
@watchables = find_watchables params
|
@watchables = find_watchables params
|
Loading…
Reference in new issue