dev_home
cxt 5 years ago
parent 505c55f240
commit 4a64c3de74

@ -1,16 +1,18 @@
class Weapps::CourseStickiesController < Weapps::BaseController
# before_action :require_wechat_login!
before_action :require_wechat_login!
before_action :teacher_allowed
def create
manage_course = current_user.manage_courses.order("sticky=1 desc, sticky_time desc, created_at desc").first
render_error("该课堂已置顶,请勿重复操作") if current_course.sticky && manage_course&.id.to_i == current_course.id
current_course.update_attributes!(sticky: 1, sticky_time: Time.now)
return render_error("该课堂已置顶,请勿重复操作") if current_course.sticky && manage_course&.id.to_i == current_course.id
current_course.update!(sticky: 1, sticky_time: Time.now)
render_ok
end
def destroy
def cancel_sticky
return render_error("该课堂未置顶,无法取消") unless current_course.sticky
current_course.update!(sticky: 1, sticky_time: Time.now)
render_ok
end
private

@ -0,0 +1,8 @@
class Weapps::CoursesController < Weapps::BaseController
before_action :require_wechat_login!
def create
return render_error("只有老师身份才能创建课堂") unless current_user.is_teacher?
end
end

@ -17,6 +17,7 @@ class Weapps::HomesController < Weapps::BaseController
end
@courses = @courses.not_deleted.not_excellent
@course_count = @courses.count
@courses = paginate(@courses.order("sticky=1 desc, sticky_time desc, created_at desc").includes(:teacher, :school))
order_str = category == "study" ? "created_at desc" : "sticky=1 desc, sticky_time desc, created_at desc"
@courses = paginate(@courses.order(order_str).includes(:teacher, :school))
end
end

@ -90,7 +90,7 @@ class Course < ApplicationRecord
}
scope :started, -> { where("start_date is null or start_date <= '#{Date.today}'") }
acts_as_taggable
# acts_as_taggable
# 课程权限判断

@ -876,7 +876,9 @@ Rails.application.routes.draw do
resource :check_account, only: [:create]
resources :searchs, only: [:index]
resources :course_stickies, only: [:create, :destroy]
resources :course_stickies, only: [:create] do
post :cancel_sticky, on: :collection
end
end
resources :users_for_partners, only: [:index]

@ -1,6 +0,0 @@
class AddStickyToCourse < ActiveRecord::Migration[5.2]
def change
add_column :courses, :sticky, :boolean, default: 0
add_column :courses, :sticky_time, :datetime
end
end

@ -0,0 +1,6 @@
class AddStickyToCourseMembers < ActiveRecord::Migration[5.2]
def change
add_column :course_members, :sticky, :boolean, default: 0
add_column :course_members, :sticky_time, :datetime
end
end
Loading…
Cancel
Save