Browse Source

add watchers_count to user

tags/v1
sylor_huang@126.com 6 years ago
parent
commit
b48fea51ca
2 changed files with 11 additions and 15 deletions
  1. +6
    -15
      app/controllers/watchers_controller.rb
  2. +5
    -0
      db/migrate/20200518065521_add_watchers_count_to_user.rb

+ 6
- 15
app/controllers/watchers_controller.rb View File

@@ -12,12 +12,7 @@ class WatchersController < ApplicationController
begin
return normal_status(2, "你还没有关注哦") unless current_user.watched?(@target)
current_user.unwatch!(@target)
if @target_type.downcase == "project"
render_ok({watchers_count: @target.watchers_count, watched: false})
else
render_ok({ watched: false})
end

render_ok({watchers_count: @target.watchers_count, watched: false})
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
@@ -29,11 +24,7 @@ class WatchersController < ApplicationController
begin
return normal_status(2, "你已关注了") if current_user.watched?(@target)
current_user.watch!(@target)
if @target_type.downcase == "project"
render_ok({watchers_count: @target.watchers_count, watched: true})
else
render_ok({ watched: true})
end
render_ok({watchers_count: @target.watchers_count, watched: true})
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
@@ -52,12 +43,12 @@ class WatchersController < ApplicationController
private

def get_target
@target_type = params[:target_type].to_s
case @target_type
target_type = params[:target_type].to_s
case target_type
when "project"
@target = @target_type.capitalize.constantize.find_by(id: params[:id])
@target = target_type.capitalize.constantize.find_by(id: params[:id])
else
@target = @target_type.capitalize.constantize.find_by(login: params[:id]) #用户
@target = target_type.capitalize.constantize.find_by(login: params[:id]) #用户
end

unless @target.present?


+ 5
- 0
db/migrate/20200518065521_add_watchers_count_to_user.rb View File

@@ -0,0 +1,5 @@
class AddWatchersCountToUser < ActiveRecord::Migration[5.2]
def change
add_column :users, :watchers_count, :integer, default: 0
end
end

Loading…
Cancel
Save