commit
f57fbe7b24
@ -0,0 +1,21 @@
|
|||||||
|
class CollectionsController < ApplicationController
|
||||||
|
|
||||||
|
before_action :require_login
|
||||||
|
|
||||||
|
def create
|
||||||
|
tip_exception("勿重复收藏") if current_user.collections.find_by(create_params).present?
|
||||||
|
current_user.collections.create!(create_params)
|
||||||
|
normal_status("收藏成功,您可以在个人主页对应的栏目中查看")
|
||||||
|
end
|
||||||
|
|
||||||
|
def cancel
|
||||||
|
collection = current_user.collections.find_by!(create_params)
|
||||||
|
collection.destroy!
|
||||||
|
normal_status("操作成功")
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def create_params
|
||||||
|
params.permit(:container_id, :container_type)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,25 @@
|
|||||||
|
class CourseVideoUploadedJob < ApplicationJob
|
||||||
|
queue_as :notify
|
||||||
|
|
||||||
|
def perform(video_id)
|
||||||
|
video = Video.select("id, user_id").find_by(id: video_id)
|
||||||
|
course_ids = video&.course_videos&.pluck(:course_id)
|
||||||
|
|
||||||
|
return unless course_ids.present?
|
||||||
|
|
||||||
|
course_members = CourseMember.where(course_id: course_ids, role: 'STUDENT').select("user_id, course_id")
|
||||||
|
Tiding.bulk_insert do |worker|
|
||||||
|
course_members.find_each do |m|
|
||||||
|
worker.add(
|
||||||
|
user_id: m.user_id,
|
||||||
|
tiding_type: 'PublishCourseVideo',
|
||||||
|
trigger_user_id: video.user_id,
|
||||||
|
container_id: video.id,
|
||||||
|
container_type: 'Video',
|
||||||
|
belong_container_type: 'Course',
|
||||||
|
belong_container_id: m.course_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -1,3 +1,7 @@
|
|||||||
class Collection < ApplicationRecord
|
class Collection < ApplicationRecord
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :container, polymorphic: true, optional: true
|
||||||
|
|
||||||
|
scope :shixuns, -> {where(container_type: 'Shixun')}
|
||||||
|
scope :subjects, -> {where(container_type: 'Subject')}
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
json.fork_from @fork_from
|
json.fork_from @fork_from
|
||||||
json.identity User.current.shixun_identity(@shixun)
|
json.identity User.current.shixun_identity(@shixun)
|
||||||
|
json.is_collect User.current&.is_collect?(@shixun)
|
||||||
|
|
||||||
json.power @power
|
json.power @power
|
||||||
json.partial! 'shixuns/top', locals: { shixun: @shixun, current_myshixun: @current_myshixun }
|
json.partial! 'shixuns/top', locals: { shixun: @shixun, current_myshixun: @current_myshixun }
|
||||||
json.secret_repository @shixun.shixun_secret_repository.present?
|
json.secret_repository @shixun.shixun_secret_repository.present?
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
class UniqIndexOnCollections < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
remove_index :collections, [:container_type, :container_id]
|
||||||
|
add_index :collections, [:container_type, :container_id], unique: true
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue