关注列表、关注与取消关注接口
This commit is contained in:
parent
bd685e16ec
commit
41fa6f02f1
|
@ -15,13 +15,37 @@
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
class WatchersController < ApplicationController
|
class WatchersController < ApplicationController
|
||||||
before_filter :require_login, :find_watchables, :only => [:watch, :unwatch]
|
before_filter :require_login#, :find_watchables, :only => [:watch, :unwatch]
|
||||||
def watch
|
def watch
|
||||||
set_watcher(@watchables, User.current, true)
|
s = Service.new
|
||||||
|
watchables = s.watch params.merge(:current_user_id => User.current.id)
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to_referer_or {render :text => (true ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||||
|
format.js { render :partial => 'set_watcher', :locals => {:user => User.current, :watched => watchables} }
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
if e.message == "404"
|
||||||
|
render_404
|
||||||
|
else
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
#set_watcher(@watchables, User.current, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unwatch
|
def unwatch
|
||||||
set_watcher(@watchables, User.current, false)
|
s = Service.new
|
||||||
|
watchables = s.unwatch params.merge(:current_user_id => User.current.id)
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to_referer_or {render :text => (false ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||||
|
format.js { render :partial => 'set_watcher', :locals => {:user => User.current, :watched => watchables} }
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
if e.message == "404"
|
||||||
|
render_404
|
||||||
|
else
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
#set_watcher(@watchables, User.current, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def join
|
def join
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
class Service
|
class Service
|
||||||
def watch params
|
def watch params
|
||||||
|
@current_user = User.find(params[:current_user_id])
|
||||||
@watchables = find_watchables params
|
@watchables = find_watchables params
|
||||||
if @watchables.nil?
|
if @watchables.nil?
|
||||||
|
raise '404'
|
||||||
end
|
end
|
||||||
set_watcher(@watchables, User.current, true)
|
set_watcher(@watchables, @current_user, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unwatch params
|
def unwatch params
|
||||||
find_watchables params
|
@current_user = User.find(params[:current_user_id])
|
||||||
set_watcher(@watchables, User.current, false)
|
@watchables = find_watchables params
|
||||||
|
if @watchables.nil?
|
||||||
|
raise '404'
|
||||||
|
end
|
||||||
|
set_watcher(@watchables, @current_user, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_watchables params
|
def find_watchables params
|
||||||
|
@ -47,5 +52,6 @@ class Service
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
watchables
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue