parent
c31c07b453
commit
e6999da273
@ -0,0 +1,25 @@
|
|||||||
|
class Users::InterestsController < Users::BaseController
|
||||||
|
before_action :require_login
|
||||||
|
before_action :private_user_resources!
|
||||||
|
|
||||||
|
def create
|
||||||
|
identity = params[:identity].to_s.strip
|
||||||
|
|
||||||
|
extension = observed_user.user_extension || observed_user.build_user_extension
|
||||||
|
return render_error('请选择职业') unless %w(teacher student professional).include?(identity)
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
extension.update_column(:identity, identity)
|
||||||
|
|
||||||
|
# 兴趣
|
||||||
|
observed_user.user_interests.delete_all
|
||||||
|
UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker|
|
||||||
|
(Repertoire.pluck(:id) & Array.wrap(params[:interest_ids]).map(&:to_i)).each do |repertoire_id|
|
||||||
|
worker.add(user_id: observed_user.id, repertoire_id: repertoire_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,4 @@
|
|||||||
|
class UserInterest < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
belongs_to :repertoire
|
||||||
|
end
|
@ -0,0 +1,8 @@
|
|||||||
|
class CreateUserInterests < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :user_interests do |t|
|
||||||
|
t.references :user
|
||||||
|
t.references :repertoire
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue