diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index c27a57c90..94c8a4ec1 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -62,15 +62,12 @@ class CoursesController < ApplicationController if @order == "mine" @courses = Course.joins(:course_members) .where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id) - .order("courses.id = 1309 DESC, courses.#{order_str} DESC") elsif @order == "created_at" # REDO:Extension @courses = Course.where(is_delete: 0, is_hidden: 0, is_end: 0) - .order("courses.id = 1309 DESC, courses.#{order_str} DESC") else # REDO:Extension @courses = Course.where(is_delete: 0, is_hidden: 0) - .order("courses.id = 1309 DESC, courses.#{order_str} DESC") end # 根据搜索关键字进一步筛选 @@ -89,14 +86,15 @@ class CoursesController < ApplicationController @courses = @courses.joins(:school, course_members: :user) .where("#{sql}", keyword: "%#{params[:search]}%").distinct end - @courses_count = @courses.size + @courses_count = @courses.count("courses.id") + @courses = @courses.order("courses.id = 1309 DESC, courses.#{order_str} DESC") # 分页 page = params[:page] || 1 limit = params[:limit] || 16 @courses = @courses.page(page).per(limit) - @courses = @courses.preload(:school, teacher: :user_extension) + @courses = @courses.preload(:school, :none_hidden_course_modules, teacher: :user_extension) end def visits_plus_one diff --git a/app/models/course.rb b/app/models/course.rb index 26672afc2..3794a8b2b 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -10,6 +10,7 @@ class Course < ApplicationRecord has_many :course_infos, dependent: :destroy # 课堂左侧导航栏的模块 has_many :course_modules, dependent: :destroy + has_many :none_hidden_course_modules, -> { not_hidden }, class_name: "CourseModule" has_many :board_course_modules, -> { board_module }, class_name: "CourseModule" has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule" has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule" diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index 2b6866517..32a7047b7 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -11,5 +11,6 @@ json.courses @courses do |course| json.is_public course.is_public json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL json.is_end course.is_end + json.first_category_url module_url(course.none_hidden_course_modules.first, course) end json.courses_count @courses_count