parent
48ea06ec8a
commit
9fbc04aa6e
@ -0,0 +1,40 @@
|
|||||||
|
class WatchersController < ApplicationController
|
||||||
|
before_action :require_login, except: %i[index]
|
||||||
|
before_action :find_user, :set_project
|
||||||
|
|
||||||
|
def index
|
||||||
|
scope = @project.watchers.includes(:user)
|
||||||
|
@watchers = paginate(scope)
|
||||||
|
end
|
||||||
|
|
||||||
|
def unfollow
|
||||||
|
begin
|
||||||
|
return normal_status(2, "你还没有关注哦") unless current_user.watched?(@project)
|
||||||
|
current_user.unwatch!(@project)
|
||||||
|
render_ok
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def follow
|
||||||
|
begin
|
||||||
|
return normal_status(2, "你已关注了") if current_user.watched?(@project)
|
||||||
|
current_user.watch!(@project)
|
||||||
|
render_ok
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_project
|
||||||
|
@project = @user.projects.find_by_identifier params[:project_id]
|
||||||
|
render_not_found("未找到’#{params[:id]}’相关的项目") unless @project
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,2 @@
|
|||||||
|
module WatchersHelper
|
||||||
|
end
|
@ -0,0 +1,3 @@
|
|||||||
|
json.name watcher.user.real_name
|
||||||
|
json.login watcher.user.login
|
||||||
|
json.image_url url_to_avatar(watcher.user)
|
@ -0,0 +1,4 @@
|
|||||||
|
json.total_count @watchers.size
|
||||||
|
json.watchers do
|
||||||
|
json.partial! 'watcher', collection: @watchers, as: :watcher
|
||||||
|
end
|
Loading…
Reference in new issue