Skip to content

Commit f882c2f

Browse files
committed
rubocop fixes
1 parent 61f4a55 commit f882c2f

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

app/controllers/api/lessons_controller.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ def index
1111
scope = params[:school_class_id] ? archive_scope.where(school_class_id: params[:school_class_id]) : archive_scope
1212
ordered_scope = scope.order(created_at: :asc)
1313
lessons_with_users = ordered_scope.accessible_by(current_ability).with_users
14-
remixes = ordered_scope.map do |lesson|
15-
next nil unless lesson&.project&.remixes.any?
16-
lesson.project&.remixes
17-
.where(user_id: current_user.id)
18-
.accessible_by(current_ability)
19-
.order(created_at: :asc)
20-
.first
21-
end
14+
remixes = user_remixes(ordered_scope)
2215
@lessons_with_users_and_remixes = lessons_with_users.zip(remixes)
2316
render :index, formats: [:json], status: :ok
2417
end
@@ -83,6 +76,22 @@ def verify_school_class_belongs_to_school
8376
raise ParameterError, 'school_class_id does not correspond to school_id'
8477
end
8578

79+
def user_remixes(lessons)
80+
lessons.map do |lesson|
81+
next nil unless lesson&.project&.remixes&.any?
82+
83+
user_remix(lesson)
84+
end
85+
end
86+
87+
def user_remix(lesson)
88+
lesson.project&.remixes
89+
&.where(user_id: current_user.id)
90+
&.accessible_by(current_ability)
91+
&.order(created_at: :asc)
92+
&.first
93+
end
94+
8695
def lesson_params
8796
base_params.merge(user_id: current_user.id)
8897
end

0 commit comments

Comments
 (0)