forked from Trustie/forgeplus
add sync to smart.doaction when follow project
This commit is contained in:
parent
aaeec77d23
commit
25f7b340d2
|
@ -14,6 +14,7 @@ class WatchersController < ApplicationController
|
|||
return normal_status(2, "你还没有关注哦") unless current_user.watched?(@target)
|
||||
current_user.unwatch!(@target)
|
||||
render_ok({watchers_count: @target.watchers_count, watched: false})
|
||||
Users::SynchronizationService.call(current_user, @target, false) if target_type == "project"
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
|
@ -26,6 +27,7 @@ class WatchersController < ApplicationController
|
|||
return normal_status(2, "你已关注了") if current_user.watched?(@target)
|
||||
current_user.watch!(@target)
|
||||
render_ok({watchers_count: @target.watchers_count, watched: true})
|
||||
Users::SynchronizationService.call(current_user, @target, true) if target_type == "project"
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
class Users::SynchronizationService
|
||||
def initialize(user, target, watched)
|
||||
@user = user
|
||||
@target = target
|
||||
@watched = watched
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def call
|
||||
if current_user.platform == "smartdoaction"
|
||||
watcher_data
|
||||
sync_to_smart_doaction
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sync_to_smart_doaction
|
||||
uri = URI("http://smart.doaction.tech/smartApi/callback/mulan/project/favorite")
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' => 'text/plain;charset=utf-8'})
|
||||
req.body = @data.to_json
|
||||
res = http.request(req)
|
||||
body = res.body
|
||||
end
|
||||
|
||||
def watcher_data
|
||||
@data = {
|
||||
email: @user.mail,
|
||||
projectId: "#{@target.owner.login}/#{@target.name}",
|
||||
operateType: @watched ==true ? 1 : 2,
|
||||
projectUrl:"https://code.mulanos.cn/#{@target.owner.login}/#{@target.name}",
|
||||
projectTitle: @target.name,
|
||||
projectDesc: @target.description,
|
||||
operateTime: Time.now.to_i,
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue